first commit

This commit is contained in:
2025-03-12 17:06:23 +01:00
commit 2241f7131f
13185 changed files with 1692479 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
<?php
function st_product_options_picker_show($namespace, $options, &$selected_ids = array())
{
$select_options = array();
$field_id = $options[0]->getProductOptionsField()->getId();
$selected = $options[0];
$last_option_id = end($options)->getId();
foreach ($options as $option)
{
$option_id = $option->getId();
$field = $option->getProductOptionsField();
$current_field_id = $field->getId();
$selected_id = isset($selected_ids[$current_field_id]) ? $selected_ids[$current_field_id] : null;
if ($field_id != $current_field_id)
{
echo '<li><label><span>' . $selected->getProductOptionsField()->getName() . '</span>' . select_tag($namespace . '[' . $selected->getProductOptionsFieldId() . ']', options_for_select($select_options, $selected->getId()), array('data-field' => $selected->getProductOptionsFieldId())) . '</label></li>';
if ($selected->hasChildren())
{
st_product_options_picker_show($namespace, $selected->getChildOptions(), $selected_ids);
}
$select_options = array();
$field_id = $current_field_id;
$selected_ids[$selected->getProductOptionsFieldId()] = $selected->getId();
$selected = $option;
}
elseif ($selected_id && $selected_id == $option_id || null === $selected_id && $option->getOptValue() == $field->getOptDefaultValue())
{
$selected = $option;
$selected_ids[$selected->getProductOptionsFieldId()] = $selected->getId();
}
$select_options[$option_id] = $option->getValue();
if ($last_option_id == $option_id)
{
echo '<li><label><span>' . $selected->getProductOptionsField()->getName() . '</span>' . select_tag($namespace . '[' . $selected->getProductOptionsFieldId() . ']', options_for_select($select_options, $selected->getId()), array('data-field' => $selected->getProductOptionsFieldId())) . '</label></li>';
$selected_ids[$selected->getProductOptionsFieldId()] = $selected->getId();
if ($selected->hasChildren())
{
st_product_options_picker_show($namespace, $selected->getChildOptions(), $selected_ids);
}
}
}
}
function object_field_select_default_value(ProductOptionsField $field, $method, $options)
{
$name = $options['control_name'];
$c = new Criteria();
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID, $field->getId());
$c->addAscendingOrderByColumn(ProductOptionsValuePeer::LFT);
$select_options = array();
foreach (ProductOptionsValuePeer::doSelectWithI18n($c, $field->getCulture()) as $value)
{
$select_options[$value->getOptValue()] = $value->getValue();
}
unset($options['control_name']);
return select_tag($name, options_for_select($select_options, $field->getOptDefaultValue(), array('include_custom' => '---')));
}
function object_template_field_select_default_value(ProductOptionsField $field, $method, $options)
{
$name = $options['control_name'];
$c = new Criteria();
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_FIELD_ID, $field->getId());
$c->addAscendingOrderByColumn(ProductOptionsDefaultValuePeer::LFT);
$select_options = array();
foreach (ProductOptionsDefaultValuePeer::doSelectWithI18n($c, $field->getCulture()) as $value)
{
$select_options[$value->getOptValue()] = $value->getValue();
}
unset($options['control_name']);
return select_tag($name, options_for_select($select_options, $field->getOptDefaultValue(), array('include_custom' => '---')));
}
function st_product_options_template_select_tag($name, $value = null, array $options = null)
{
$fc = stFunctionCache::getInstance('stProductOptions');
$select_options = $fc->cacheCall(function ()
{
$c = new Criteria();
$c->addAscendingOrderByColumn(ProductOptionsTemplatePeer::OPT_NAME);
$templates = ProductOptionsTemplatePeer::doSelect($c);
$results = array();
/**
* @var ProductOptionsTemplate[] $templates
*/
foreach ($templates as $template)
{
if ($template->countProductOptionsDefaultValues() > 1)
{
$results[$template->getId()] = $template->getOptName();
}
}
return $results;
}, array(), array('id' => 'templates'));
return $select_options ? select_tag($name, options_for_select($select_options, $value, $options)) : null;
}

View File

@@ -0,0 +1,453 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
*
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @package stProductOptionsPlugin
* @subpackage helpers
* @copyright SOTE (www.sote.pl)
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
* @version $Id: stProductOptionsHelper.php 17609 2012-04-02 07:40:06Z marcin $
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
* @author Marcin Butlak <marcin.butlak@sote.pl>
*/
use_helper('stTheme', 'Form');
function get_asset_data_for_options($option_ids, $options = null, $object = false)
{
$result = array();
$asset = null;
sfLoader::loadHelpers(array('Helper', 'Url', 'stAsset'));
if($options == null)
{
if(!is_array($option_ids))
{
$ids = explode('-', $option_ids);
}
else
{
$ids = $option_ids;
}
$options = ProductOptionsValuePeer::retrieveByPks($ids);
}
if(count($options) && $asset = end($options)->getsfAsset())
{
if($object)
{
return $asset;
}
$link = url_for('@stProductShowImage?folder=' . end($options)->getProduct()->getOptImageFolderId() . '&image=' . $asset->getFilename());
$src = st_asset_image_path($asset, 'large');
$alt = (string)$asset->getDescription();
if(!empty($link) && !empty($src))
{
$result['link'] = $link;
$result['src'] = $src;
$result['photo_title'] = $alt;
}
}
else
{
$marked_path = false;
foreach($options as $index => $option)
{
if(!$marked_path || !$option->getParent()->isRoot() || empty($asset_remeber))
{
if($marked_path && $option->getParent()->isRoot())
{
$marked_path = false;
}
if($asset = $option->getsfAsset())
{
$asset_remeber = $asset;
$link = url_for('@stProductShowImage?folder=' . $option->getProduct()->getOptImageFolderId() . '&image=' . $asset->getFilename());
$src = st_asset_image_path($asset, 'large');
$alt = (string)$asset->getDescription();
if(!empty($link) && !empty($src))
{
$result['link'] = $link;
$result['src'] = $src;
$result['photo_title'] = $alt;
}
}
if($option->getId() == end($options)->getId())
{
$marked_path = true;
}
}
else
{
break;
}
}
if($object)
{
return !empty($asset_remeber) ? $asset_remeber : null;
}
}
return $result;
}
/**
* Get data information about changes in product card
*
* @return array()
*/
function get_update_data($selected_option, $selected_ids = null)
{
$result = array();
if($selected_ids)
{
$option_ids = explode('-', $selected_ids);
$options = ProductOptionsValuePeer::retrieveByPksWithProduct($option_ids);
}
// zdjecie
$result = get_asset_data_for_options(null, $options);
// stan magazynowy
if(!empty($options))
{
$result['stock'] = get_stock_for_options(null, $options);
}
else
{
$result['stock'] = $selected_option->getStock();
}
// dostępność
if($result['stock'] !== null)
{
if($selected_option->getProduct()->getAvailabilityId()===null)
{
$result['avalibility'] = show_availability_by_stock($result['stock']);
}
}
$product_config = stConfig::getInstance(sfContext::getInstance(), null, 'stProduct');
$product_config->load();
$result['check_stock'] = ($product_config->get('depository_basket') || ProductOptionsValuePeer::$hide_no_stock);
$i18n = sfContext::getInstance()->getI18N();
$result['basket_disabled'] = $i18n->__('Brak w magazynie', '', 'stProductOptionsFrontend');
$result['basket_enabled'] = $i18n->__('Dodaj do koszyka', '', 'stBasket');
// cena
$price = array();
//ustawianie modyfiaktora ceny;
// ProductOptionsValuePeer::setSelectedItems($selected_option->getProduct()->getId(), explode('-', $selected_ids));
$price['brutto'] = $selected_option->getProduct()->getPriceBrutto();
// ProductOptionsValuePeer::setSelectedItems($selected_option->getProduct()->getId(), explode('-', $selected_ids));
$price['netto'] = $selected_option->getProduct()->getPriceNetto();
//$price = modify_price($selected_option, null, $selected_ids);
if(!empty($price))
{
if(isset($price['brutto']))
{
$result['price_brutto'] = st_price($price['brutto'], true, true);
}
if(isset($price['netto']))
{
$result['price_netto'] = st_price($price['netto'], true, true);
}
}
return $result;
}
function show_availability_by_stock($stock)
{
$c = new Criteria();
$c->add(AvailabilityPeer::STOCK_FROM,$stock,Criteria::LESS_EQUAL);
$c->addDescendingOrderByColumn(AvailabilityPeer::STOCK_FROM);
if($availability=AvailabilityPeer::doSelectOne($c))
{
$availability=$availability->getAvailabilityName();
}
else
{
$availability = null;
}
return $availability;
}
function st_product_options_get_view($product)
{
static $smarty = null;
if (null === $smarty)
{
st_theme_use_stylesheet('stProductOptionsPlugin.css');
$smarty = new stSmarty('stProductOptionsFrontend');
}
$smarty->assign('product_options', $product->getPriceModifiers());
return $smarty->fetch('options_view.html');
}
/**
*
* @param Product $product
* @param array $selected_ids
* @return mixed
* @throws PropelException
*/
function st_product_options_get_form($product, $selected_ids = array())
{
if (!$product->getConfiguration()->get('disable_default_option_select', false) && count($selected_ids)==0) return "";
$debug = sfConfig::get('sf_logging_enabled') && sfConfig::get('sf_debug');
if ($debug)
{
$timer = sfTimerManager::getTimer('__SOTE helper st_product_options_get_form');
}
st_theme_use_stylesheet("stProductOptionsViewselect.css");
$smarty = new stSmarty('stProductOptionsFrontend');
$options = ProductOptionsValuePeer::doSelectByProduct($product);
$price_type = ProductOptionsValuePeer::getPriceType($product);
ob_start();
_st_product_options_form_content($smarty, $product, $options, $selected_ids, $price_type);
$smarty->assign('form_head', form_tag('#', array('id' => 'st_update_product_options_form', "autocomplete"=>"off" )));
$smarty->assign('options', ob_get_clean());
$smarty->assign('head', '<ul id="st_product_options_form">');
$smarty->assign('foot', '</ul>');
$smarty->assign('form_foot', '</form>');
$smarty->assign('config', $product->getConfiguration());
$smarty->assign('url', '@stProductOptionsFrontend?action=ajaxNewUpdateProduct&product_id='.$product->getId());
$ret = $smarty->fetch('options_template.html');
if ($debug)
{
$timer->addTime();
}
return $ret;
}
/**
*
* @param stSmarty $smarty
* @param Product $product
* @param ProductOptionsValue[] $options
* @param array $selected_ids
* @param string $price_type
* @return void
* @throws PropelException
*/
function _st_product_options_form_content($smarty, $product, $options, $selected_ids = array(), $price_type)
{
if (empty($options))
{
return;
}
$productConfig = $product->getConfiguration();
$selectDefaultOptions = !$productConfig->get('disable_default_option_select', false);
$select_options = array();
$field = $options[0]->getProductOptionsField();
$selected = $selectDefaultOptions ? $options[0] : null;
$lastOptionId = end($options)->getId();
foreach ($options as $option)
{
$optionId = $option->getId();
$currentField = $option->getProductOptionsField();
$selected_id = isset($selected_ids[$currentField->getId()]) ? $selected_ids[$currentField->getId()] : null;
if ($field->getId() != $currentField->getId())
{
if (is_object($field->getProductOptionsFilter()) && $field->getProductOptionsFilter()->getFilterType()==2)
{
_st_product_options_form_color($smarty, $select_options, $field, $selected);
}
else
{
_st_product_options_form_select($smarty, $select_options, $field, $selected);
}
if (null !== $selected && $selected->hasChildren())
{
_st_product_options_form_content($smarty, $product, $selected->getChildOptions($productConfig->get('hide_options_with_empty_stock')), $selected_ids, $price_type);
}
$select_options = array();
$field = $currentField;
$selected = $selectDefaultOptions ? $option : null;
}
if ($selected_id && $selected_id == $optionId || $selectDefaultOptions && null === $selected_id && $option->getOptValue() == $currentField->getOptDefaultValue())
{
$selected = $option;
}
$select_options[$optionId]['label'] = $option->getValue();
$select_options[$optionId]['color'] = $option->getUseImageAsColor() ? $option->getColorImagePath() : '#'.$option->getColor();
$select_options[$optionId]['modify'] = _st_product_options_form_option_price($product, $option, $price_type);
$select_options[$optionId]['stock'] = $option->getStock() ? $option->getStock() : 0;
$select_options[$optionId]['instance'] = $option;
if ($lastOptionId == $optionId)
{
if (is_object($currentField->getProductOptionsFilter()) && $currentField->getProductOptionsFilter()->getFilterType()==2)
{
_st_product_options_form_color($smarty, $select_options, $currentField, $selected);
}
else
{
_st_product_options_form_select($smarty, $select_options, $currentField, $selected);
}
if (null !== $selected && $selected->hasChildren())
{
_st_product_options_form_content($smarty, $product, $selected->getChildOptions($productConfig->get('hide_options_with_empty_stock')), $selected_ids, $price_type);
}
}
}
}
/**
* Wyświetla wybór opcji
*
* @param stSmarty $smarty
* @param array $select_options
* @param ProductOptionsField $field
* @param ProductOptionsValue|null $selected
* @return void
*/
function _st_product_options_form_select($smarty, $select_options, $field, $selected = null)
{
$smarty->assign('field_instance', $field);
$smarty->assign('field_name', 'st_product_options['.$field->getId().']');
$smarty->assign('field_id', 'st_product_options_'.$field->getId());
$smarty->assign('field_label', $field->getName());
$smarty->assign('field_required', stConfig::getInstance('stProduct')->get('disable_default_option_select', false));
$smarty->assign('selected', null !== $selected ? $selected->getId() : null);
$smarty->assign('options', $select_options);
$smarty->display('options_view_select.html');
}
/**
* Wyświetla wybór koloru opcji
*
* @param stSmarty $smarty
* @param array $select_options
* @param ProductOptionsField $field
* @param ProductOptionsValue|null $selected
* @return void
*/
function _st_product_options_form_color($smarty, $select_options, $field, $selected = null)
{
$smarty->assign('field_instance', $field);
$smarty->assign('field_name', 'st_product_options['.$field->getId().']');
$smarty->assign('field_id', 'st_product_options_'.$field->getId());
$smarty->assign('field_label', $field->getName());
$smarty->assign('field_required', stConfig::getInstance('stProduct')->get('disable_default_option_select', false));
$smarty->assign('selected', null !== $selected ? $selected->getId() : null);
$smarty->assign('options', $select_options);
$smarty->assign('unavail_image', st_theme_image_tag('stProductOptionsPlugin/unavail.png', array('class'=>'st_product_option-color_unavail')));
$smarty->display('options_view_color_select.html');
}
function _st_product_options_form_option_price(Product $product, $option, $price_type)
{
if (!$product->isPriceVisible()) {
return '';
}
$option_price = $option->getPrice();
if ($option_price && substr($option_price, -1) != '%')
{
$product_currency = $product->getCurrency();
$currency = stCurrency::getInstance(sfContext::getInstance())->get();
$prefix = $option_price{0} == '+' || $option_price{0} == '-' ? $option_price{0} : null;
$option_price = ltrim($option_price, '+-');
if ($product_currency->getExchange() != 1 && $product_currency->getId() != $currency->getId())
{
$option_price = $product_currency->exchange($option_price, true, $product->getCurrencyExchange());
$option_price = $currency->exchange($option_price);
}
if ($product_currency->getExchange() != 1)
{
$price_type = 'brutto';
}
$view = $product->getConfiguration()->get('price_view');
if ($price_type == 'brutto')
{
$tax = $product->getTax();
$taxRateByCountry = $tax->getTaxRateByCountry();
if ($tax && null !== $taxRateByCountry)
{
$option_price = stPrice::extract($option_price, $tax->getDefaultTaxRate());
$option_price = stPrice::calculate($option_price, $taxRateByCountry);
}
}
if (($view == 'only_gross' || $view == 'gross_net') && $price_type == 'netto')
{
$option_price = stPrice::calculate($option_price, $product->getVatValue());
}
elseif (($view == 'only_net' || $view == 'net_gross') && $price_type == 'brutto')
{
$option_price = stPrice::extract($option_price, $product->getVatValue());
}
if ($product_currency->getExchange() == 1)
{
$option_price = $currency->exchange($option_price);
}
$option_price = $prefix.st_currency_format($option_price);
}
return $option_price;
}

View File

@@ -0,0 +1,216 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stReview opartej na licencji (Professional License SOTE).
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsDefaultValue extends BaseProductOptionsDefaultValue
{
protected static $version = 1;
/**
* Przeciążenie hydrate
*
* @param ResultSet $rs
* @param int $startcol
* @return object
*/
public function hydrate(ResultSet $rs, $startcol = 1)
{
$this->setCulture(stLanguage::getHydrateCulture());
return parent::hydrate($rs, $startcol);
}
public function toArray($keyType = BasePeer::TYPE_PHPNAME)
{
$results = parent::toArray($keyType);
if ($keyType == BasePeer::TYPE_FIELDNAME)
{
$results['value'] = $this->getValue();
}
return $results;
}
/**
* Przeciążenie getPriceType
*
* @return string
*/
public function getPriceType($check = false)
{
if($this->isRoot())
{
$result = $this->price_type;
if($result === null)
{
foreach($this->getDescendants() as $option)
{
$result = $option->getPriceType(true);
if($result!==null)
{
$this->setPriceType($result);
break;
}
}
if($result === null)
{
$this->setPriceType(0);
}
}
if($result === 0)
{
$config = stConfig::getInstance('stProduct');
$result = $config->get('global_price_netto') ? 'netto' : 'brutto';
}
return $result;
}
else
{
if($check)
{
return $this->price_type;
}
else
{
$c = new Criteria();
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_TEMPLATE_ID, $this->getProductOptionsTemplateId());
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_DEFAULT_VALUE_ID, null, Criteria::ISNULL);
$root = ProductOptionsDefaultValuePeer::doSelectOne($c);
return $root->getPriceType();
}
}
}
/**
* Przeciążenie getValue
*
* @return string
*/
public function getValue()
{
if ($this->getCulture() == stLanguage::getOptLanguage())
{
return stLanguage::getDefaultValue($this, __METHOD__);
}
$v = parent::getValue();
if (is_null($v)) $v = stLanguage::getDefaultValue($this, __METHOD__);
return $v;
}
/**
* Przeciążenie setValue
*
* @param string $v
*/
public function setValue($v)
{
if ($this->getCulture() == stLanguage::getOptLanguage())
{
stLanguage::setDefaultValue($this, __METHOD__, $v);
}
parent::setValue($v);
}
public function getCurrency()
{
return stCurrency::getInstance(sfContext::getInstance())->get();
}
public function save($con = null)
{
if ($this->getOptVersion()!=ProductOptionsDefaultValue::$version) {
$this->setOptVersion(ProductOptionsDefaultValue::$version);
}
parent::save($con);
$field = ProductOptionsFieldPeer::retrieveByPk($this->product_options_field_id);
if ($field && $this->getDepth()>0) {
$field->setOptValueId($this->getParent()->getId());
$field->save();
}
}
public function delete($con = null)
{
$sql = sprintf('DELETE %1$s, %2$s FROM %1$s LEFT JOIN %2$s ON %8$s = %7$s, %3$s WHERE %10$s = %11$s AND %4$s > %5$s AND %4$s < %6$s AND %7$s = %9$s',
ProductOptionsFieldPeer::TABLE_NAME,
ProductOptionsFieldI18nPeer::TABLE_NAME,
ProductOptionsDefaultValuePeer::TABLE_NAME,
ProductOptionsDefaultValuePeer::LFT,
$this->getLft(),
$this->getRgt(),
ProductOptionsFieldPeer::ID,
ProductOptionsFieldI18nPeer::ID,
ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_FIELD_ID,
ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_TEMPLATE_ID,
$this->getProductOptionsTemplateId()
);
$ret = parent::delete();
$this->deleteColorImage();
return $ret;
}
public function getParentId()
{
return $this->getProductOptionsDefaultValueId();
}
public function clearI18ns()
{
if ($this->collProductOptionsDefaultValueI18ns)
{
unset($this->collProductOptionsDefaultValueI18ns);
$this->collProductOptionsDefaultValueI18ns = null;
}
}
public function getColorImagePath($system = false)
{
return ProductOptionsValuePeer::getColorImagePath($this->getProductOptionsTemplateId(), $this->getId(), $this->getColor(), $system, '/uploads/default-options');
}
public function deleteColorImage()
{
if ($this->getUseImageAsColor() && is_file($this->getColorImagePath(true)))
{
unlink($this->getColorImagePath(true));
}
}
public function getColorImageDir($system = false)
{
return ProductOptionsValuePeer::getColorImageDir($this->getProductOptionsTemplateId(), $system, '/uploads/default-options');
}
public function setColorImage($v)
{
$this->setColor($v);
}
public function getColorImage()
{
return $this->getColor();
}
}
$columns = array('left' => ProductOptionsDefaultValuePeer::LFT,
'right' => ProductOptionsDefaultValuePeer::RGT,
'parent' => ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_DEFAULT_VALUE_ID,
'scope' => ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_TEMPLATE_ID,
'depth' => ProductOptionsDefaultValuePeer::DEPTH);
sfPropelBehavior::add('ProductOptionsDefaultValue', array('actasnestedset' => array('columns' => $columns)));

View File

@@ -0,0 +1,17 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stReview opartej na licencji (Professional License SOTE).
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsDefaultValueI18n extends BaseProductOptionsDefaultValueI18n
{
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
*
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @package stProductOptionsPlugin
* @subpackage libs
* @copyright SOTE (www.sote.pl)
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
* @version $Id: ProductOptionsDefaultValueI18nPeer.php 210 2009-09-01 13:21:28Z michal $
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*/
class ProductOptionsDefaultValueI18nPeer extends BaseProductOptionsDefaultValueI18nPeer
{
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
*
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @package stProductOptionsPlugin
* @subpackage libs
* @copyright SOTE (www.sote.pl)
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
* @version $Id: ProductOptionsDefaultValuePeer.php 210 2009-09-01 13:21:28Z michal $
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*/
class ProductOptionsDefaultValuePeer extends BaseProductOptionsDefaultValuePeer
{
public static function addOrderCriteria(Criteria $c)
{
$c->addAscendingOrderByColumn(ProductOptionsFieldPeer::FIELD_ORDER);
$c->addAscendingOrderByColumn(self::PRODUCT_OPTIONS_FIELD_ID);
$c->addAscendingOrderByColumn(self::LFT);
}
public static function doSelectRootAsJsTreeFormat(ProductOptionsTemplate $template)
{
self::setPostHydrateMethod(array('ProductOptionsDefaultValuePeer', 'jsTreeFormatHydrate'));
$c = new Criteria();
$c->add(self::PRODUCT_OPTIONS_TEMPLATE_ID, $template->getId());
$c->add(self::PRODUCT_OPTIONS_FIELD_ID, null, Criteria::ISNULL);
$result = self::doSelectWithI18n($c, $template->getCulture());
self::setPostHydrateMethod(null);
return $result;
}
public static function doSelectByFieldId($fieldId, $culture)
{
$c = new Criteria();
if ($fieldId)
{
$c->add(self::PRODUCT_OPTIONS_FIELD_ID, $fieldId);
}
$c->addJoin(self::PRODUCT_OPTIONS_FIELD_ID, ProductOptionsFieldPeer::ID);
self::addOrderCriteria($c);
return self::doSelectWithI18n($c, $culture);
}
public static function doSelectByFieldIdAsJsTreeFormat($fieldId, $culture)
{
self::setPostHydrateMethod(array('ProductOptionsDefaultValuePeer', 'jsTreeFormatHydrate'));
$results = self::doSelectByFieldId($fieldId, $culture);
self::setPostHydrateMethod(null);
return $results;
}
public static function jsTreeFormatHydrate(ProductOptionsDefaultValue $value)
{
if ($value->isRoot() && $value->hasChildren())
{
$state = "open";
}
else
{
$state = $value->hasChildren() ? "closed" : "item_leaf";
}
return array(
"data" => $value->isRoot() ? $value->getProductOptionsTemplate()->getOptName() : $value->getValue(),
"attr" => array("id" => "value-".$value->getId(), "rel" => $value->isRoot() ? "root" : "value"),
"metadata" => array("id" => $value->getId()),
"state" => $state,
"children" => $value->isRoot() && $value->hasChildren() ? ProductOptionsFieldPeer::doSelectByDefaultValueIdAsJsTreeFormat($value->getId(), $value->getCulture()) : null,
);
}
}

View File

@@ -0,0 +1,222 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsField extends BaseProductOptionsField
{
public $_duplicated = null;
protected $updateDefaultValue = false;
protected $productUpdate = true;
public function __toString()
{
return $this->getName();
}
public function disableProductUpdate()
{
$this->productUpdate = false;
}
public function enableProductUpdate()
{
$this->productUpdate = true;
}
public function copyInto($copyObj, $deepCopy = false)
{
parent::copyInto($copyObj, $deepCopy);
$copyObj->_duplicated = true;
}
public function toArray($keyType = BasePeer::TYPE_PHPNAME)
{
$results = parent::toArray($keyType);
if ($keyType == BasePeer::TYPE_FIELDNAME)
{
$results['name'] = $this->getName();
}
return $results;
}
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
{
parent::fromArray($arr, $keyType);
if ($keyType == BasePeer::TYPE_FIELDNAME)
{
if (isset($arr['name']))
{
$this->setName($arr['name']);
}
}
}
/**
* Returns ProductOptionsValue object of given product id
* with the same value as default one.
*
* @param $product_id
* @return ProductOptionsValue object
*/
public function getDefaultNode($product_id)
{
$c = new Criteria();
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID, $this->getId());
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product_id);
$c->addJoin(ProductOptionsValuePeer::ID, ProductOptionsValueI18nPeer::ID);
foreach (ProductOptionsValuePeer::doSelect($c) as $value)
{
$value->setCulture($this->getCulture());
if ($value->getValue() == $this->getDefaultValue()) return $value;
}
}
public function getValues()
{
$c = new Criteria();
$c->addAscendingOrderByColumn(ProductOptionsValuePeer::LFT);
return $this->getProductOptionsValues($c);
}
public function getDefaultValues()
{
$c = new Criteria();
$c->addAscendingOrderByColumn(ProductOptionsDefaultValuePeer::LFT);
return $this->getProductOptionsDefaultValues($c);
}
/**
* Przeciążenie hydrate
*
* @param ResultSet $rs
* @param int $startcol
* @return object
*/
public function hydrate(ResultSet $rs, $startcol = 1)
{
$this->setCulture(stLanguage::getHydrateCulture());
return parent::hydrate($rs, $startcol);
}
/**
* Przeciążenie getName
*
* @return string
*/
public function getName()
{
if ($this->getCulture() == stLanguage::getOptLanguage())
{
return stLanguage::getDefaultValue($this, __METHOD__);
}
$v = parent::getName();
if (is_null($v)) $v = stLanguage::getDefaultValue($this, __METHOD__);
return $v;
}
/**
* Przeciążenie setName
*
* @param string $v
*/
public function setName($v)
{
if ($this->getCulture() == stLanguage::getOptLanguage())
{
stLanguage::setDefaultValue($this, __METHOD__, $v);
}
parent::setName($v);
}
/**
* Przeciążenie getDefaultValue
*
* @return string
*/
public function getDefaultValue()
{
if ($this->getCulture() == stLanguage::getOptLanguage())
{
return stLanguage::getDefaultValue($this, __METHOD__);
}
$v = parent::getDefaultValue();
if (is_null($v)) $v = stLanguage::getDefaultValue($this, __METHOD__);
return $v;
}
/**
* Przeciążenie setDefaultValue
*
* @param string $v
*/
public function setDefaultValue($v)
{
if ($this->getCulture() == stLanguage::getOptLanguage())
{
stLanguage::setDefaultValue($this, __METHOD__, $v);
}
parent::setDefaultValue($v);
}
public function save($con = null)
{
if (!$this->product_options_template_id && !isset($this->_duplicated) && !$this->isNew())
{
$options = $this->getProductOptionsValues();
if (!empty($options))
{
if ($this->isColumnModified(ProductOptionsFieldPeer::IS_ACTIVE) || $this->isColumnModified(ProductOptionsFieldPeer::PRODUCT_OPTIONS_FILTER_ID))
{
foreach ($options as $option)
{
$option->disableProductUpdate();
$option->setIsActive($this->getIsActive());
$option->setOptFilterId($this->getProductOptionsFilterId());
$option->save();
}
}
if ($this->productUpdate && $this->isColumnModified(ProductOptionsFieldPeer::IS_ACTIVE))
{
ProductOptionsValuePeer::updateStock($options[0]->getProductId());
}
if ($this->productUpdate && $this->isColumnModified(ProductOptionsFieldPeer::PRODUCT_OPTIONS_FILTER_ID) || $this->isColumnModified(ProductOptionsFieldPeer::IS_ACTIVE))
{
ProductOptionsValuePeer::updateProductColor($options[0]->getProductId());
}
}
}
return parent::save($con);
}
public function clearI18ns()
{
if ($this->collProductOptionsFieldI18ns)
{
unset($this->collProductOptionsFieldI18ns);
$this->collProductOptionsFieldI18ns = null;
}
}
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsFieldI18n extends BaseProductOptionsFieldI18n
{
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsFieldI18nPeer extends BaseProductOptionsFieldI18nPeer
{
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsFieldPeer extends BaseProductOptionsFieldPeer
{
public static function doSelectByValueIdAsJsTreeFormat($valueId, $culture)
{
self::setPostHydrateMethod(function(ProductOptionsField $field) {
return array(
"data" => $field->getName(),
"attr" => array("id" => "field-".$field->getId(), "rel" => "field"),
"metadata" => array("id" => $field->getId()),
"state" => "closed",
);
});
$c = new Criteria();
$c->addJoin(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID, self::ID);
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_VALUE_ID, $valueId);
$c->addAscendingOrderByColumn(self::FIELD_ORDER);
$c->addAscendingOrderByColumn(self::ID);
$c->addGroupByColumn(self::ID);
$results = self::doSelectWithI18n($c, $culture);
self::setPostHydrateMethod(null);
return $results;
}
public static function doSelectByDefaultValueIdAsJsTreeFormat($valueId, $culture)
{
self::setPostHydrateMethod(function(ProductOptionsField $field) {
return array(
"data" => $field->getName(),
"attr" => array("id" => "field-".$field->getId(), "rel" => "field"),
"metadata" => array("id" => $field->getId()),
"state" => "closed",
);
});
$c = new Criteria();
$c->addJoin(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_FIELD_ID, self::ID);
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_DEFAULT_VALUE_ID, $valueId);
$c->addAscendingOrderByColumn(self::FIELD_ORDER);
$c->addAscendingOrderByColumn(self::ID);
$c->addGroupByColumn(self::ID);
$results = self::doSelectWithI18n($c, $culture);
self::setPostHydrateMethod(null);
return $results;
}
/**
* Method perform an INSERT on the database, given a ProductOptionsField or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsField object containing data that is used to create the INSERT statement.
* @param Connection $con the connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsFieldPeer:doInsert:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsFieldPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null)
{
$con = Propel::getConnection(self::DATABASE_NAME);
}
if ($values instanceof Criteria)
{
$criteria = clone $values; // rename for clarity
$criteria->remove(ProductOptionsFieldPeer::ID);
}
else
{
$criteria = $values->buildCriteria(); // build Criteria from ProductOptionsField object
if (!$values->isColumnModified(ProductOptionsFieldPeer::ID))
{
$criteria->remove(ProductOptionsFieldPeer::ID); // remove pkey col since this table uses auto-increment
}
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try
{
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->begin();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
}
catch (PropelException $e)
{
$con->rollback();
throw $e;
}
foreach (sfMixer::getCallables('BaseProductOptionsFieldPeer:doInsert:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsFieldPeer', $values, $con, $pk);
}
return $pk;
}
}

View File

@@ -0,0 +1,105 @@
<?php
/**
* Subclass for representing a row from the 'st_product_options_filter' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model
*/
class ProductOptionsFilter extends BaseProductOptionsFilter
{
public function __toString()
{
return $this->getName();
}
/**
* Przeciążenie hydrate
*
* @param ResultSet $rs
* @param int $startcol
* @return object
*/
public function hydrate(ResultSet $rs, $startcol = 1)
{
$this->setCulture(stLanguage::getHydrateCulture());
return parent::hydrate($rs, $startcol);
}
/**
* Przeciążenie getName
*
* @return string
*/
public function getName()
{
if ($this->getCulture() == stLanguage::getOptLanguage())
{
return stLanguage::getDefaultValue($this, __METHOD__);
}
$v = parent::getName();
if (is_null($v)) $v = stLanguage::getDefaultValue($this, __METHOD__);
return $v;
}
/**
* Przeciążenie setName
*
* @param string $v
*/
public function setName($v)
{
if ($this->getCulture() == stLanguage::getOptLanguage())
{
stLanguage::setDefaultValue($this, __METHOD__, $v);
}
parent::setName($v);
}
public function getPriceFrom($currency = true)
{
if (SF_APP == 'frontend' && $currency) {
return stCurrency::getInstance(sfContext::getInstance())->get()->exchange($this->price_from, false, null);
}
return $this->price_from;
}
public function getPriceTo($currency = true)
{
if (SF_APP == 'frontend' && $currency) {
return stCurrency::getInstance(sfContext::getInstance())->get()->exchange($this->price_to, false, null);
}
return $this->price_to;
}
public function getFilterTypeLabel(sfI18N $i18n = null)
{
$types = ProductOptionsFilterPeer::getFilterTypes($i18n);
return isset($types[$this->filter_type]) ? $types[$this->filter_type] : null;
}
public function save($con = null)
{
$ret = parent::save();
stFunctionCache::getInstance('stProductOptionsPlugin')->removeAll();
return $ret;
}
public function delete($con = null)
{
$ret = parent::delete($con);
stFunctionCache::getInstance('stProductOptionsPlugin')->removeAll();
return $ret;
}
}

View File

@@ -0,0 +1,12 @@
<?php
/**
* Subclass for representing a row from the 'st_product_options_filter_i18n' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model
*/
class ProductOptionsFilterI18n extends BaseProductOptionsFilterI18n
{
}

View File

@@ -0,0 +1,12 @@
<?php
/**
* Subclass for performing query and update operations on the 'st_product_options_filter_i18n' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model
*/
class ProductOptionsFilterI18nPeer extends BaseProductOptionsFilterI18nPeer
{
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* Subclass for performing query and update operations on the 'st_product_options_filter' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model
*/
class ProductOptionsFilterPeer extends BaseProductOptionsFilterPeer
{
/**
* @deprecated
*/
const PRICE_FILTER = 3;
const COLOR_FILTER = 2;
const NORMAL_FILTER = 1;
protected static $optionFiltersPool = null;
protected static $byNamePool = array();
public static function getFilterTypes(sfI18N $i18n = null)
{
if (null === $i18n)
{
$i18n = sfContext::getInstance()->getI18N();
}
return array(
self::NORMAL_FILTER => $i18n->__('Zwykły filtr', null, 'stProductOptionsBackend'),
self::COLOR_FILTER => $i18n->__('Filtr koloru', null, 'stProductOptionsBackend'),
);
}
public static function getOptionFiltersCached()
{
if (null === self::$optionFiltersPool)
{
$fc = stFunctionCache::getInstance('stProductOptionsPlugin');
self::$optionFiltersPool = $fc->cacheCall(array('ProductOptionsFilterPeer', 'getOptionFilters'));
}
return self::$optionFiltersPool;
}
public static function getOptionFiltersForSelect()
{
$results = self::getOptionFiltersCached();
return $results && $results['id'] ? $results['id'] : array();
}
public static function getOptionFilters()
{
$c = new Criteria();
$c->add(ProductOptionsFilterPeer::FILTER_TYPE, self::PRICE_FILTER, Criteria::NOT_EQUAL);
$c->addAscendingOrderByColumn(ProductOptionsFilterPeer::OPT_NAME);
$results = array('id' => array(), 'name' => array());
foreach (ProductOptionsFilterPeer::doSelect($c) as $filter)
{
$results['id'][$filter->getId()] = $filter;
$results['name'][$filter->getOptName()] = $filter->getId();
}
return $results;
}
/**
* Pobiera filtr po id
*
* @param int $id
* @return ProductOptionsFilter
* @throws sfCacheException
*/
public static function retrieveById($id)
{
$results = self::getOptionFiltersCached();
return isset($results['id'][$id]) ? $results['id'][$id] : null;
}
/**
* Pobiera filtr po nazwie
*
* @param string $name
* @return ProductOptionsFilter
* @throws sfCacheException
*/
public static function retrieveByName($name)
{
$results = self::getOptionFiltersCached();
return isset($results['name'][$name]) && isset($results['id'][$results['name'][$name]]) ? $results['id'][$results['name'][$name]] : null;
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsTemplate extends BaseProductOptionsTemplate
{
protected $culture;
public function getAdminGeneratorTitle()
{
return $this->getOptName();
}
public function getCulture()
{
return $this->culture;
}
public function setCulture($culture)
{
$this->culture = $culture;
}
public function save($con = null)
{
$isNew = $this->isNew();
$ret = parent::save($con);
if ($isNew)
{
$root = new ProductOptionsDefaultValue();
$root->setProductOptionsTemplate($this);
$root->makeRoot();
$root->save();
}
$this->cacheClear();
return $ret;
}
public function delete($con = null)
{
$ret = parent::delete($con);
$this->cacheClear();
return $ret;
}
public function cacheClear()
{
$fc = stFunctionCache::getInstance('stProductOptions');
$fc->removeById('templates');
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsTemplatePeer extends BaseProductOptionsTemplatePeer
{
public static function getTemplateNames($culture)
{
$c = new Criteria();
$c->addAscendingOrderByColumn(ProductOptionsTemplatePeer::OPT_NAME);
$templates = ProductOptionsTemplatePeer::doSelect($c);
$params = array();
foreach ($templates as $template)
{
$template->setCulture($culture);
$params[] = array('name'=>$template->getName(), 'value'=>$template->getId());
}
return $params;
}
}

View File

@@ -0,0 +1,443 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsValue extends BaseProductOptionsValue
{
protected static
$productPool = array();
protected $childOptions = null;
public $_duplicated = null;
protected $productUpdate = true;
protected $oldColorImagePath = null;
public function disableProductUpdate()
{
$this->productUpdate = false;
}
public function toArray($keyType = BasePeer::TYPE_PHPNAME)
{
$results = parent::toArray($keyType);
if ($keyType == BasePeer::TYPE_FIELDNAME)
{
$results['value'] = $this->getValue();
}
return $results;
}
public function enableProductUpdate()
{
$this->productUpdate = true;
}
public function copyInto($copyObj, $deepCopy = false)
{
parent::copyInto($copyObj, $deepCopy);
$copyObj->_duplicated = true;
}
/**
* Przeciazenie setPrice, zeby nie zapisywalo pustego stringa
*
* @return void
**/
public function setPrice($v)
{
if($v === '')
{
$v = null;
}
parent::setPrice($v);
}
public function setProductOptionsDefaultValueId($v)
{
$this->setProductOptionsValueId($v);
}
public function getChildOptions($hide_with_empty_stock = false)
{
if (null === $this->childOptions)
{
$c = new Criteria();
$c->addAscendingOrderByColumn(ProductOptionsFieldPeer::FIELD_ORDER);
$c->addAscendingOrderByColumn(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID);
$c->addAscendingOrderByColumn(ProductOptionsValuePeer::LFT);
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_VALUE_ID, $this->getId());
$c->add(ProductOptionsValuePeer::IS_ACTIVE, true);
if ($this->getProduct()->hasStockManagmentWithOptions() && $hide_with_empty_stock)
{
$c->add(ProductOptionsValuePeer::STOCK, 0, Criteria::GREATER_THAN);
}
$this->childOptions = ProductOptionsValuePeer::doSelectJoinProductOptionsField($c);
}
return $this->childOptions;
}
public function insertAsLastChildOf(ProductOptionsValue $value)
{
$this->setPriceType($value->getPriceType());
if (!$value->getIsActive())
{
$this->setIsActive(false);
}
return parent::insertAsLastChildOf($value);
}
public function getPriceType()
{
if (null === $this->price_type)
{
if ($this->isNew() || $this->isRoot())
{
$config = stConfig::getInstance('stProduct');
$this->setPriceType($config->get('global_price_netto') ? 'netto' : 'brutto');
}
else
{
$this->price_type = ProductOptionsValuePeer::doSelectRoot($this->getProduct())->getPriceType();
}
}
return $this->price_type;
}
/**
* Przeciążenie hydrate
*
* @param ResultSet $rs
* @param int $startcol
* @return object
*/
public function hydrate(ResultSet $rs, $startcol = 1)
{
$this->setCulture(stLanguage::getHydrateCulture());
return parent::hydrate($rs, $startcol);
}
/**
* Przeciążenie getValue
*
* @return string
*/
public function getValue()
{
if ($this->getCulture() == stLanguage::getOptLanguage())
{
return stLanguage::getDefaultValue($this, __METHOD__);
}
$v = parent::getValue();
if (is_null($v)) $v = stLanguage::getDefaultValue($this, __METHOD__);
return $v;
}
/**
* Przeciążenie setValue
*
* @param string $v
*/
public function setValue($v)
{
if ($this->getCulture() == stLanguage::getOptLanguage())
{
stLanguage::setDefaultValue($this, __METHOD__, $v);
}
parent::setValue($v);
}
/**
* Undocumented function
*
* @param Connection $con
* @return Product
*/
public function getProduct($con = null)
{
$id = $this->getProductId();
if ($id && !isset(self::$productPool[$id]))
{
self::$productPool[$id] = parent::getProduct($con);
}
return self::$productPool[$id];
}
/**
* Przeciążenie funkcji save
*
* @param $con
*/
public function save($con = null)
{
$removeOldColorImage = $this->isColumnModified(ProductOptionsValuePeer::COLOR);
if ($this->getOptVersion()!=ProductOptionsValuePeer::version)
{
$this->setOptVersion(ProductOptionsValuePeer::version);
}
if (!$this->isNew() && ($this->isColumnModified(ProductOptionsValuePeer::STOCK) || $this->isColumnModified(ProductOptionsValuePeer::PRICE)))
{
AllegroAuctionPeer::updateRequiresSync($this->getProductId(), $this->getId());
}
if (!$this->isNew() && $this->isColumnModified(ProductOptionsValuePeer::IS_ACTIVE))
{
ProductOptionsValuePeer::updateIsActive($this);
}
if (!isset($this->_duplicated) && $this->productUpdate)
{
if($this->isNew())
{
$con = Propel::getConnection();
$sql = sprintf('UPDATE %1$s SET %2$s = %2$s + 1 WHERE %3$s = %4$s',
ProductPeer::TABLE_NAME,
ProductPeer::OPT_HAS_OPTIONS,
ProductPeer::ID,
$this->getProductId()
);
$con->executeQuery($sql);
if (null === $this->opt_filter_id && $this->getProductOptionsField())
{
$filter_id = $this->getProductOptionsField()->getProductOptionsFilterId();
$this->setOptFilterId($filter_id);
}
}
if ($this->isRoot() && $this->isColumnModified(ProductOptionsValuePeer::PRICE_TYPE))
{
ProductOptionsValuePeer::doUpdatePriceType($this);
}
$modified = $this->modifiedColumns;
$ret = parent::save($con);
$this->modifiedColumns = $modified;
if ($this->product_id && !$this->isRoot())
{
if ($this->isColumnModified(ProductOptionsValuePeer::STOCK) || $this->isColumnModified(ProductOptionsValuePeer::IS_ACTIVE))
{
ProductOptionsValuePeer::updateStock($this->getProduct());
}
if ($this->isColumnModified(ProductOptionsValuePeer::IS_ACTIVE) || $this->isColumnModified(ProductOptionsValuePeer::STOCK) || $this->isColumnModified(ProductOptionsValuePeer::COLOR) || $this->isColumnModified(ProductOptionsValuePeer::SF_ASSET_ID) || $this->isColumnModified(ProductOptionsValuePeer::IS_ACTIVE))
{
ProductOptionsValuePeer::updateProductColor($this->product_id);
}
}
$this->resetModified();
}
else
{
$ret = parent::save($con);
}
if ($removeOldColorImage && null !== $this->oldColorImagePath && is_file($this->oldColorImagePath))
{
unlink($this->oldColorImagePath);
}
return $ret;
}
/**
* Przeciążenie funkcji delete
*
* @param $con
**/
public function delete($con = null)
{
$con = Propel::getConnection();
$sql = sprintf('UPDATE %1$s SET %2$s = %2$s - 1 WHERE %3$s = %4$s',
ProductPeer::TABLE_NAME,
ProductPeer::OPT_HAS_OPTIONS,
ProductPeer::ID,
$this->getProductId()
);
$con->executeQuery($sql);
$sql = sprintf('DELETE %1$s, %2$s FROM %1$s LEFT JOIN %2$s ON %8$s = %7$s, %3$s WHERE %10$s = %11$s AND %4$s > %5$s AND %4$s < %6$s AND %7$s = %9$s',
ProductOptionsFieldPeer::TABLE_NAME,
ProductOptionsFieldI18nPeer::TABLE_NAME,
ProductOptionsValuePeer::TABLE_NAME,
ProductOptionsValuePeer::LFT,
$this->getLft(),
$this->getRgt(),
ProductOptionsFieldPeer::ID,
ProductOptionsFieldI18nPeer::ID,
ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID,
ProductOptionsValuePeer::PRODUCT_ID,
$this->getProductId()
);
$con->executeQuery($sql);
parent::delete($con);
$this->deleteColorImage();
if ($this->product_id)
{
ProductOptionsValuePeer::updateStock($this->product_id);
if ($this->color)
{
ProductOptionsValuePeer::updateProductColor($this->product_id);
}
}
}
/**
* Zwraca opcje nadrzędne ignorując korzeń
*
* @param bool $includeSelf Uwzględnij aktualną opcję w ścieżce
* @return ProductOptionsValue[]
*/
public function getPathWithoutRoot($includeSelf = false)
{
$results = $this->getPath('doSelectWithoutRoot');
if ($includeSelf)
{
$results[] = $this;
}
return $results;
}
public function getParentId()
{
return $this->getProductOptionsValueId();
}
public function isRoot()
{
return $this->product_options_value_id === null;
}
public function isLeaf()
{
return $this->rgt - $this->lft == 1;
}
public function getLevel()
{
return $this->depth;
}
public function hasChildren()
{
return $this->rgt - $this->lft > 1;
}
public function clearI18ns()
{
if ($this->collProductOptionsValueI18ns)
{
unset($this->collProductOptionsValueI18ns);
$this->collProductOptionsValueI18ns = null;
}
}
public static function setProductPool(Product $product)
{
self::$productPool[$product->getId()] = $product;
}
public function getColorImagePath($system = false)
{
return ProductOptionsValuePeer::getColorImagePath($this->getProductId(), $this->getId(), $this->getColor(), $system);
}
public function deleteColorImage()
{
if ($this->getUseImageAsColor() && is_file($this->getColorImagePath(true)))
{
unlink($this->getColorImagePath(true));
}
}
public function getColorImageDir($system = false)
{
return ProductOptionsValuePeer::getColorImageDir($this->getProductId(), $system);
}
public function setColorImage($v)
{
if (!$this->isNew() && null !== $this->getColor() && $this->getUseImageAsColor())
{
$this->oldColorImagePath = $this->getColorImagePath(true);
}
$this->setColor($v);
}
public function getColorImage()
{
return $this->getColor();
}
/**
* Undocumented function
*
* @return void
*/
public function getCurrency()
{
return $this->getProduct()->hasLocalCurrency() ? $this->getProduct()->getCurrency() : stCurrency::getInstance(sfContext::getInstance())->get();
}
public function getProductUom()
{
sfLoader::loadHelpers('stProduct', 'stProduct');
return st_product_uom($this->getProduct());
}
public static function clearStaticPool()
{
self::$productPool = array();
}
}
$columns = array('left' => ProductOptionsValuePeer::LFT,
'right' => ProductOptionsValuePeer::RGT,
'parent' => ProductOptionsValuePeer::PRODUCT_OPTIONS_VALUE_ID,
'scope' => ProductOptionsValuePeer::PRODUCT_ID,
'depth' => ProductOptionsValuePeer::DEPTH);
sfPropelBehavior::add('ProductOptionsValue', array('actasnestedset' => array('columns' => $columns)));

View File

@@ -0,0 +1,17 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsValueI18n extends BaseProductOptionsValueI18n
{
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsValueI18nPeer extends BaseProductOptionsValueI18nPeer
{
}

View File

@@ -0,0 +1,656 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class ProductOptionsValuePeer extends BaseProductOptionsValuePeer
{
protected static
$selectedItems = array(),
$doSelectByProduct = array(),
$getPriceType = array(),
$colorFilters = null;
const version = 1;
public static $hide_no_stock = false;
/**
* Zwraca listę opcji bez korzenia
*
* @param Criteria $c
* @param mixed $con
* @return array
* @throws PropelException
*/
public static function doSelectWithoutRoot(Criteria $c, $con = null)
{
$results = [];
$c = clone $c;
$c->add(self::PRODUCT_OPTIONS_VALUE_ID, null, Criteria::ISNOTNULL);
return self::doSelectJoinProductOptionsField($c, $con);
}
public static function doCountLeafsJoinProduct(Criteria $c = null, $con = null)
{
if($c == null)
{
$c = new Criteria();
}
$user = sfContext::getInstance()->getUser();
$filters = sfContext::getInstance()->getRequest()->getParameter('filters', array());
$c->add(self::LFT, self::RGT.'-'.self::LFT.'=1', Criteria::CUSTOM);
$c->addAscendingOrderByColumn(self::LFT);
$c->addJoin(self::PRODUCT_OPTIONS_FIELD_ID, BaseProductOptionsFieldPeer::ID);
$c->addJoin(self::ID, ProductOptionsValueI18nPeer::ID.' AND '.ProductOptionsValueI18nPeer::CULTURE.'=\''.$user->getCulture().'\'', Criteria::LEFT_JOIN);
$c->add(BaseProductOptionsFieldPeer::OPT_NAME, null, Criteria::ISNOTNULL);
return self::doCountJoinProduct($c, $con);
}
public static function doSelectLeafsJoinProduct(Criteria $c = null, $con = null)
{
if($c == null)
{
$c = new Criteria();
}
$user = sfContext::getInstance()->getUser();
$filters = sfContext::getInstance()->getRequest()->getParameter('filters', array());
$c->add(self::LFT, self::RGT.'-'.self::LFT.'=1', Criteria::CUSTOM);
$c->addAscendingOrderByColumn(self::LFT);
$c->addJoin(self::PRODUCT_OPTIONS_FIELD_ID, BaseProductOptionsFieldPeer::ID);
$c->addJoin(self::ID, ProductOptionsValueI18nPeer::ID.' AND '.ProductOptionsValueI18nPeer::CULTURE.'=\''.$user->getCulture().'\'', Criteria::LEFT_JOIN);
$c->add(BaseProductOptionsFieldPeer::OPT_NAME, null, Criteria::ISNOTNULL);
return self::doSelectJoinProduct($c, $con);
}
public static function updateIsActive(ProductOptionsValue $option)
{
$sql = sprintf('UPDATE %s SET %s = ? WHERE %s = ? AND %s BETWEEN ? AND ?', self::TABLE_NAME, self::IS_ACTIVE, self::PRODUCT_ID, self::LFT);
$ps = Propel::getConnection()->prepareStatement($sql);
$ps->setBoolean(1, $option->getIsActive());
$ps->setInt(2, $option->getProductId());
$ps->setInt(3, $option->getLft());
$ps->setInt(4, $option->getRgt());
return $ps->executeUpdate();
$s = new Criteria();
$s->add(self::LFT, sprintf('%s BETWEEN %d AND %d', self::LFT, $option->getLft(), $option->getRgt()));
$s->add(self::PRODUCT_ID, $option->getProductId());
$u = new Criteria();
$u->add(self::IS_ACTIVE, $option->getIsActive());
BasePeer::doUpdate($s, $u, Propel::getConnection());
}
public static function updateStock($product, $update_product = true, $return_stock = true)
{
if ($product)
{
$is_object = is_object($product);
if ($is_object && !$product->hasStockManagmentWithOptions())
{
return $product->getStock();
}
$id = $is_object ? $product->getId() : $product;
$con = Propel::getConnection();
$con->executeQuery(sprintf('UPDATE %1$s v LEFT JOIN %1$s c ON c.LFT BETWEEN v.LFT AND v.RGT AND c.PRODUCT_ID = %2$s AND c.RGT - c.LFT = 1 AND c.STOCK > 0 AND c.IS_ACTIVE = 1 SET v.STOCK = IFNULL(c.STOCK, 0) WHERE v.PRODUCT_ID = %2$s AND v.RGT - v.LFT > 1 AND v.IS_ACTIVE = 1',
self::TABLE_NAME,
$id
));
if ($update_product || $return_stock)
{
$stock = self::getStock($product);
if ($update_product)
{
stDepository::set($product, $stock);
}
return $stock;
}
}
return null;
}
public static function getStock($product)
{
$config = stConfig::getInstance('stProduct');
if ('max' == $config->get('product_options_stock_computation', 'max'))
{
return self::getMaxStock($product);
}
return self::getSumStock($product);
}
public static function getSumStock($product)
{
if (is_object($product) && !$product instanceof Product)
{
throw new InvalidArgumentException(sprintf('Przekazany obiekt musi być instancją Product (przekazany: %s)', get_class($product)));
}
$id = is_object($product) ? $product->getId() : $product;
$c = new Criteria();
$c->addSelectColumn('SUM('.self::STOCK.')');
$c->add(self::PRODUCT_ID, $id);
$c->add(self::IS_ACTIVE, true);
$c->add(self::LFT, sprintf('%s - %s = 1', self::RGT, self::LFT), Criteria::CUSTOM);
$rs = self::doSelectRs($c);
if ($rs && $rs->next())
{
$row = $rs->getRow();
return !empty($row[0]) ? $row[0] : 0;
}
return 0;
}
public static function getMaxStock($product)
{
if ($product)
{
if (is_object($product) && !$product instanceof Product)
{
throw new InvalidArgumentException(sprintf('Przekazany obiekt musi być instancją Product (przekazany: %s)', get_class($product)));
}
$id = is_object($product) ? $product->getId() : $product;
$c = new Criteria();
$c->addSelectColumn('MAX('.self::STOCK.')');
$c->add(self::IS_ACTIVE, true);
$c->add(self::PRODUCT_ID, $id);
$rs = self::doSelectRs($c);
if ($rs && $rs->next())
{
$row = $rs->getRow();
return !empty($row[0]) ? $row[0] : 0;
}
}
return 0;
}
public static function updateTotalStock($product_id)
{
self::updateStock($product_id);
}
public static function unsetTemplate($product)
{
$c = new Criteria();
$c->add(self::DEPTH, 0);
$c->add(self::PRODUCT_ID, $product->getId());
$root = self::doSelectOne($c);
if(is_object($root))
{
$root->setProductOptionsTemplateId(null);
$root->save();
}
}
public static function doSelectByIds($ids)
{
$options = array();
foreach ($ids as $id)
{
$option = self::retrieveByPk($id);
if (null === $option)
{
return array();
}
$options[] = $option;
}
return $options;
}
public static function getProductOptionsStock($product)
{
$c = new Criteria();
$c->add(self::PRODUCT_ID,$product->getId());
$c->add(self::LFT, self::RGT.'-'.self::LFT.'=1', Criteria::CUSTOM);
$stock = 0;
foreach (self::doSelect($c) as $option)
{
$stock+= $option->getStock();
}
return $stock;
}
public static function retrieveByPkWithProduct($pk)
{
$c = new Criteria();
$c->add(self::ID, $pk);
$options = self::doSelectJoinProduct($c);
return isset($options[0]) ? $options[0] : null;
}
public static function retrieveByPksWithProduct($pks)
{
$c = new Criteria();
$c->add(self::ID, $pks, Criteria::IN);
return self::doSelectJoinProduct($c);
}
public static function setSelectedItems($id, $items = array())
{
self::$selectedItems[$id] = $items;
}
public static function getSelectedItems($id)
{
if (isset(self::$selectedItems[$id])) return self::$selectedItems[$id];
return array();
}
/**
* Zwraca opcje root produktu
*
* @param Product|int $product Id lub instancja modelu produktu
* @return ProductOptionsValue|null
*/
public static function getRoot($product)
{
$c = new Criteria();
$c->add(self::PRODUCT_ID, is_object($product) ? $product->getId() : $product);
$c->add(self::PRODUCT_OPTIONS_VALUE_ID, null, Criteria::ISNULL);
return self::doSelectOne($c);
}
/**
* Zwraca lub tworzy opcje root produktu
*
* @param Product|int $product Id lub instancja modelu produktu
* @return ProductOptionsValue
*/
public static function getOrCreateRoot($product, string $priceType = null)
{
$root = self::getRoot($product);
if (null === $root)
{
$root = new ProductOptionsValue();
$root->setPriceType($priceType);
$root->setProductId($product->getId());
$root->makeRoot();
$root->save();
}
return $root;
}
public static function getPriceType($product)
{
$id = is_object($product) ? $product->getId() : $product;
if (!isset(self::$getPriceType[$id]))
{
$c = new Criteria();
$c->add(self::PRODUCT_OPTIONS_VALUE_ID, null, Criteria::ISNULL);
$c->add(self::PRICE_TYPE, null, Criteria::ISNOTNULL);
$c->addSelectColumn(self::PRICE_TYPE);
$c->add(self::PRODUCT_ID, $id);
$c->setLimit(1);
$rs = self::doSelectRS($c);
$config = stConfig::getInstance(null, 'stProduct');
self::$getPriceType[$id] = $rs->next() ? $rs->getString(1) : $config->get('price_type');
}
return self::$getPriceType[$id];
}
public static function doSelectByProduct($product, $hide_no_stock = true)
{
$id = $product->getId();
if (!isset(self::$doSelectByProduct[$id]))
{
$c = new Criteria();
$c->add(self::PRODUCT_ID, $id);
self::addOrderCriteria($c);
$c->add(self::DEPTH, 1);
$c->add(self::IS_ACTIVE, true);
if ($hide_no_stock)
{
self::addHideWithEmptyStockCriteria($product, $c);
}
self::$doSelectByProduct[$id] = self::doSelectJoinProductOptionsField($c);
}
return self::$doSelectByProduct[$id];
}
/**
* Dodaje kryteria ukrywania opcji z 0 stanem magazynowym
*
* @param Product $product
* @param Criteria|Criterion $c
* @param bool $addOr
* @return void
*/
public static function addHideWithEmptyStockCriteria(Product $product, $c, $addOr = false)
{
if ($product->getStockManagment() == ProductPeer::STOCK_PRODUCT_OPTIONS && $product->getConfiguration()->get('hide_options_with_empty_stock'))
{
$value = sprintf('(%1$s IS NULL OR %1$s > 0)', self::STOCK);
if ($c instanceof Criterion)
{
$criteria = new Criteria();
$criterion = $criteria->getNewCriterion(self::STOCK, $value, Criteria::CUSTOM);
if ($addOr)
{
$c->addOr($criterion);
}
else
{
$c->addAnd($criterion);
}
}
else
{
if ($addOr)
{
$c->addOr(self::STOCK, $value, Criteria::CUSTOM);
}
else
{
$c->addAnd(self::STOCK, $value, Criteria::CUSTOM);
}
}
}
}
public static function getColorImageDir($product_id, $system = false, $root_path = null)
{
if (null === $root_path)
{
$root_path = '/uploads/options';
}
$path = $root_path.'/'.$product_id;
if ($system)
{
return sfConfig::get('sf_web_dir').$path;
}
return $path;
}
public static function getColorImagePath($product_id, $option_id, $color_image_name, $system = false, $root_path = null)
{
return self::getColorImageDir($product_id, $system, $root_path).'/'.$option_id.'-'.$color_image_name;
}
public static function addOrderCriteria(Criteria $c)
{
$c->addAscendingOrderByColumn(ProductOptionsFieldPeer::FIELD_ORDER);
$c->addAscendingOrderByColumn(self::PRODUCT_OPTIONS_FIELD_ID);
$c->addAscendingOrderByColumn(self::LFT);
}
public static function clearImportHash($id)
{
ExportMd5HashPeer::clearHash($id, 'Product', 'product_options');
}
public static function clearStatic()
{
self::$selectedItems = array();
self::$doSelectByProduct = array();
self::$getPriceType = array();
self::$colorFilters = null;
}
public static function updateProductColor($product)
{
$object = is_object($product);
$product_id = $object ? $product->getId() : $product;
if (null === self::$colorFilters)
{
$c = new Criteria();
$c->addSelectColumn(ProductOptionsFilterPeer::ID);
$c->add(ProductOptionsFilterPeer::FILTER_TYPE, 2);
$rs = ProductOptionsFilterPeer::doSelectRs($c);
self::$colorFilters = array();
while($rs->next())
{
self::$colorFilters[] = $rs->getInt(1);
}
}
$colors = array();
if (self::$colorFilters)
{
$c = new Criteria();
$c->addSelectColumn(self::ID);
$c->addSelectColumn(self::COLOR);
$c->addSelectColumn(self::STOCK);
$c->addSelectColumn(self::USE_IMAGE_AS_COLOR);
$c->addSelectColumn(self::SF_ASSET_ID);
$c->add(self::IS_ACTIVE, true);
$c->add(self::PRODUCT_ID, $product_id);
$c->add(self::OPT_FILTER_ID, self::$colorFilters, Criteria::IN);
$c->addAscendingOrderByColumn(self::LFT);
$c->addGroupByColumn(self::COLOR);
$rs = self::doSelectRs($c);
while($rs->next())
{
$row = $rs->getRow();
$colors[] = array(
'color' => $row[3] ? self::getColorImagePath($product_id, $row[0], $row[1]) : $row[1],
'stock' => $row[2],
'image_as_color' => $row[3],
'image_id' => $row[4],
);
}
}
if (!$object)
{
$sel = new Criteria();
$sel->add(ProductPeer::ID, $product_id);
$up = new Criteria();
$up->add(ProductPeer::OPTIONS_COLOR, serialize($colors));
BasePeer::doUpdate($sel, $up, Propel::getConnection());
}
else
{
$product->setOptionsColor($colors);
}
}
public static function doUpdatePriceType(ProductOptionsValue $value)
{
$sel = new Criteria();
$sel->add(self::PRODUCT_ID, $value->getProductId());
$up = new Criteria();
$up->add(self::PRICE_TYPE, $value->getPriceType());
return BasePeer::doUpdate($sel, $up, Propel::getConnection());
}
public static function doInsert($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsValuePeer:doInsert:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsValuePeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
$criteria->remove(self::ID);
} else {
$criteria = $values->buildCriteria(); // build Criteria from ProductOptionsValue object
if (!$values->isColumnModified(self::ID)) {
$criteria->remove(self::ID); // remove pkey col since this table uses auto-increment
}
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->begin();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch(PropelException $e) {
$con->rollback();
throw $e;
}
foreach (sfMixer::getCallables('BaseProductOptionsValuePeer:doInsert:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsValuePeer', $values, $con, $pk);
}
return $pk;
}
public static function doSelectRoot(Product $product)
{
$c = new Criteria();
$c->add(self::PRODUCT_ID, $product->getId());
$c->add(self::PRODUCT_OPTIONS_FIELD_ID, null, Criteria::ISNULL);
$c->setLimit(1);
$results = self::doSelectWithI18n($c, $product->getCulture());
return $results ? $results[0] : null;
}
public static function doSelectRootAsJsTreeFormat(Product $product)
{
self::setPostHydrateMethod(array('ProductOptionsValuePeer', 'jsTreeFormatHydrate'));
$result = self::doSelectRoot($product);
self::setPostHydrateMethod(null);
return $result;
}
public static function doSelectByFieldId($fieldId, $culture)
{
$c = new Criteria();
if ($fieldId)
{
$c->add(self::PRODUCT_OPTIONS_FIELD_ID, $fieldId);
}
$c->addJoin(self::PRODUCT_OPTIONS_FIELD_ID, ProductOptionsFieldPeer::ID);
self::addOrderCriteria($c);
return self::doSelectWithI18n($c, $culture);
}
public static function doSelectByFieldIdAsJsTreeFormat($fieldId, $culture)
{
self::setPostHydrateMethod(array('ProductOptionsValuePeer', 'jsTreeFormatHydrate'));
$results = self::doSelectByFieldId($fieldId, $culture);
self::setPostHydrateMethod(null);
return $results;
}
public static function jsTreeFormatHydrate(ProductOptionsValue $value)
{
if ($value->isRoot() && $value->hasChildren())
{
$state = "open";
}
else
{
$state = $value->hasChildren() ? "closed" : "item_leaf";
}
return array(
"data" => $value->isRoot() ? $value->getProduct()->getName() : $value->getValue(),
"attr" => array("id" => "value-".$value->getId(), "rel" => $value->isRoot() ? "root" : "value"),
"metadata" => array("id" => $value->getId()),
"state" => $state,
"children" => $value->isRoot() && $value->hasChildren() ? ProductOptionsFieldPeer::doSelectByValueIdAsJsTreeFormat($value->getId(), $value->getCulture()) : null,
);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* This class adds structure of 'st_product_options_default_value_i18n' table to 'propel' DatabaseMap object.
*
*
*
* These statically-built map classes are used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package plugins.stProductOptionsPlugin.lib.model.map
*/
class ProductOptionsDefaultValueI18nMapBuilder {
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsDefaultValueI18nMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_product_options_default_value_i18n');
$tMap->setPhpName('ProductOptionsDefaultValueI18n');
$tMap->setUseIdGenerator(false);
$tMap->addForeignPrimaryKey('ID', 'Id', 'int' , CreoleTypes::INTEGER, 'st_product_options_default_value', 'ID', true, null);
$tMap->addPrimaryKey('CULTURE', 'Culture', 'string', CreoleTypes::VARCHAR, true, 7);
$tMap->addColumn('VALUE', 'Value', 'string', CreoleTypes::VARCHAR, false, 128);
} // doBuild()
} // ProductOptionsDefaultValueI18nMapBuilder

View File

@@ -0,0 +1,102 @@
<?php
/**
* This class adds structure of 'st_product_options_default_value' table to 'propel' DatabaseMap object.
*
*
*
* These statically-built map classes are used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package plugins.stProductOptionsPlugin.lib.model.map
*/
class ProductOptionsDefaultValueMapBuilder {
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsDefaultValueMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_product_options_default_value');
$tMap->setPhpName('ProductOptionsDefaultValue');
$tMap->setUseIdGenerator(true);
$tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
$tMap->addColumn('UPDATED_AT', 'UpdatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
$tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null);
$tMap->addForeignKey('PRODUCT_OPTIONS_TEMPLATE_ID', 'ProductOptionsTemplateId', 'int', CreoleTypes::INTEGER, 'st_product_options_template', 'ID', true, null);
$tMap->addForeignKey('PRODUCT_OPTIONS_DEFAULT_VALUE_ID', 'ProductOptionsDefaultValueId', 'int', CreoleTypes::INTEGER, 'st_product_options_default_value', 'ID', false, null);
$tMap->addForeignKey('PRODUCT_OPTIONS_FIELD_ID', 'ProductOptionsFieldId', 'int', CreoleTypes::INTEGER, 'st_product_options_field', 'ID', false, null);
$tMap->addColumn('PRICE', 'Price', 'string', CreoleTypes::VARCHAR, false, 16);
$tMap->addColumn('WEIGHT', 'Weight', 'string', CreoleTypes::VARCHAR, false, 10);
$tMap->addColumn('LFT', 'Lft', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('RGT', 'Rgt', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('OPT_VALUE', 'OptValue', 'string', CreoleTypes::VARCHAR, false, 128);
$tMap->addColumn('PRICE_TYPE', 'PriceType', 'string', CreoleTypes::VARCHAR, false, 6);
$tMap->addColumn('DEPTH', 'Depth', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('OPT_VERSION', 'OptVersion', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('COLOR', 'Color', 'string', CreoleTypes::VARCHAR, false, 128);
$tMap->addColumn('USE_IMAGE_AS_COLOR', 'UseImageAsColor', 'boolean', CreoleTypes::BOOLEAN, false, null);
$tMap->addColumn('OLD_PRICE', 'OldPrice', 'double', CreoleTypes::DECIMAL, false, 10);
$tMap->addColumn('PUM', 'Pum', 'double', CreoleTypes::DECIMAL, false, 10);
} // doBuild()
} // ProductOptionsDefaultValueMapBuilder

View File

@@ -0,0 +1,74 @@
<?php
/**
* This class adds structure of 'st_product_options_field_i18n' table to 'propel' DatabaseMap object.
*
*
*
* These statically-built map classes are used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package plugins.stProductOptionsPlugin.lib.model.map
*/
class ProductOptionsFieldI18nMapBuilder {
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsFieldI18nMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_product_options_field_i18n');
$tMap->setPhpName('ProductOptionsFieldI18n');
$tMap->setUseIdGenerator(false);
$tMap->addForeignPrimaryKey('ID', 'Id', 'int' , CreoleTypes::INTEGER, 'st_product_options_field', 'ID', true, null);
$tMap->addPrimaryKey('CULTURE', 'Culture', 'string', CreoleTypes::VARCHAR, true, 7);
$tMap->addColumn('NAME', 'Name', 'string', CreoleTypes::VARCHAR, false, 128);
$tMap->addColumn('DEFAULT_VALUE', 'DefaultValue', 'string', CreoleTypes::VARCHAR, false, 128);
} // doBuild()
} // ProductOptionsFieldI18nMapBuilder

View File

@@ -0,0 +1,88 @@
<?php
/**
* This class adds structure of 'st_product_options_field' table to 'propel' DatabaseMap object.
*
*
*
* These statically-built map classes are used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package plugins.stProductOptionsPlugin.lib.model.map
*/
class ProductOptionsFieldMapBuilder {
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsFieldMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_product_options_field');
$tMap->setPhpName('ProductOptionsField');
$tMap->setUseIdGenerator(true);
$tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
$tMap->addColumn('UPDATED_AT', 'UpdatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
$tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null);
$tMap->addForeignKey('PRODUCT_OPTIONS_TEMPLATE_ID', 'ProductOptionsTemplateId', 'int', CreoleTypes::INTEGER, 'st_product_options_template', 'ID', false, null);
$tMap->addForeignKey('PRODUCT_OPTIONS_FILTER_ID', 'ProductOptionsFilterId', 'int', CreoleTypes::INTEGER, 'st_product_options_filter', 'ID', false, null);
$tMap->addColumn('IS_ACTIVE', 'IsActive', 'boolean', CreoleTypes::BOOLEAN, true, null);
$tMap->addColumn('REQUIRED', 'Required', 'boolean', CreoleTypes::BOOLEAN, false, null);
$tMap->addColumn('OPT_NAME', 'OptName', 'string', CreoleTypes::VARCHAR, false, 128);
$tMap->addColumn('OPT_DEFAULT_VALUE', 'OptDefaultValue', 'string', CreoleTypes::VARCHAR, false, 128);
$tMap->addColumn('OPT_VALUE_ID', 'OptValueId', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('FIELD_ORDER', 'FieldOrder', 'int', CreoleTypes::INTEGER, false, null);
} // doBuild()
} // ProductOptionsFieldMapBuilder

View File

@@ -0,0 +1,72 @@
<?php
/**
* This class adds structure of 'st_product_options_filter_i18n' table to 'propel' DatabaseMap object.
*
*
*
* These statically-built map classes are used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package plugins.stProductOptionsPlugin.lib.model.map
*/
class ProductOptionsFilterI18nMapBuilder {
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsFilterI18nMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_product_options_filter_i18n');
$tMap->setPhpName('ProductOptionsFilterI18n');
$tMap->setUseIdGenerator(false);
$tMap->addForeignPrimaryKey('ID', 'Id', 'int' , CreoleTypes::INTEGER, 'st_product_options_filter', 'ID', true, null);
$tMap->addPrimaryKey('CULTURE', 'Culture', 'string', CreoleTypes::VARCHAR, true, 7);
$tMap->addColumn('NAME', 'Name', 'string', CreoleTypes::VARCHAR, false, 128);
} // doBuild()
} // ProductOptionsFilterI18nMapBuilder

View File

@@ -0,0 +1,84 @@
<?php
/**
* This class adds structure of 'st_product_options_filter' table to 'propel' DatabaseMap object.
*
*
*
* These statically-built map classes are used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package plugins.stProductOptionsPlugin.lib.model.map
*/
class ProductOptionsFilterMapBuilder {
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsFilterMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_product_options_filter');
$tMap->setPhpName('ProductOptionsFilter');
$tMap->setUseIdGenerator(true);
$tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
$tMap->addColumn('UPDATED_AT', 'UpdatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
$tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null);
$tMap->addColumn('OPT_NAME', 'OptName', 'string', CreoleTypes::VARCHAR, false, 128);
$tMap->addColumn('FILTER_TYPE', 'FilterType', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('RANK', 'Rank', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('PRICE_FROM', 'PriceFrom', 'double', CreoleTypes::DOUBLE, false, null);
$tMap->addColumn('PRICE_TO', 'PriceTo', 'double', CreoleTypes::DOUBLE, false, null);
$tMap->addColumn('IS_VISIBLE', 'IsVisible', 'boolean', CreoleTypes::BOOLEAN, false, null);
} // doBuild()
} // ProductOptionsFilterMapBuilder

View File

@@ -0,0 +1,74 @@
<?php
/**
* This class adds structure of 'st_product_options_template' table to 'propel' DatabaseMap object.
*
*
*
* These statically-built map classes are used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package plugins.stProductOptionsPlugin.lib.model.map
*/
class ProductOptionsTemplateMapBuilder {
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsTemplateMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_product_options_template');
$tMap->setPhpName('ProductOptionsTemplate');
$tMap->setUseIdGenerator(true);
$tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
$tMap->addColumn('UPDATED_AT', 'UpdatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
$tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null);
$tMap->addColumn('OPT_NAME', 'OptName', 'string', CreoleTypes::VARCHAR, false, 255);
} // doBuild()
} // ProductOptionsTemplateMapBuilder

View File

@@ -0,0 +1,72 @@
<?php
/**
* This class adds structure of 'st_product_options_value_i18n' table to 'propel' DatabaseMap object.
*
*
*
* These statically-built map classes are used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package plugins.stProductOptionsPlugin.lib.model.map
*/
class ProductOptionsValueI18nMapBuilder {
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsValueI18nMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_product_options_value_i18n');
$tMap->setPhpName('ProductOptionsValueI18n');
$tMap->setUseIdGenerator(false);
$tMap->addForeignPrimaryKey('ID', 'Id', 'int' , CreoleTypes::INTEGER, 'st_product_options_value', 'ID', true, null);
$tMap->addPrimaryKey('CULTURE', 'Culture', 'string', CreoleTypes::VARCHAR, true, 7);
$tMap->addColumn('VALUE', 'Value', 'string', CreoleTypes::VARCHAR, false, 128);
} // doBuild()
} // ProductOptionsValueI18nMapBuilder

View File

@@ -0,0 +1,118 @@
<?php
/**
* This class adds structure of 'st_product_options_value' table to 'propel' DatabaseMap object.
*
*
*
* These statically-built map classes are used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package plugins.stProductOptionsPlugin.lib.model.map
*/
class ProductOptionsValueMapBuilder {
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsValueMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_product_options_value');
$tMap->setPhpName('ProductOptionsValue');
$tMap->setUseIdGenerator(true);
$tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
$tMap->addColumn('UPDATED_AT', 'UpdatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
$tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null);
$tMap->addForeignKey('SF_ASSET_ID', 'SfAssetId', 'int', CreoleTypes::INTEGER, 'sf_asset', 'ID', false, null);
$tMap->addForeignKey('PRODUCT_ID', 'ProductId', 'int', CreoleTypes::INTEGER, 'st_product', 'ID', true, null);
$tMap->addForeignKey('PRODUCT_OPTIONS_TEMPLATE_ID', 'ProductOptionsTemplateId', 'int', CreoleTypes::INTEGER, 'st_product_options_template', 'ID', false, null);
$tMap->addForeignKey('PRODUCT_OPTIONS_VALUE_ID', 'ProductOptionsValueId', 'int', CreoleTypes::INTEGER, 'st_product_options_value', 'ID', false, null);
$tMap->addForeignKey('PRODUCT_OPTIONS_FIELD_ID', 'ProductOptionsFieldId', 'int', CreoleTypes::INTEGER, 'st_product_options_field', 'ID', false, null);
$tMap->addColumn('IS_ACTIVE', 'IsActive', 'boolean', CreoleTypes::BOOLEAN, true, null);
$tMap->addColumn('PRICE', 'Price', 'string', CreoleTypes::VARCHAR, false, 16);
$tMap->addColumn('WEIGHT', 'Weight', 'string', CreoleTypes::VARCHAR, false, 10);
$tMap->addColumn('LFT', 'Lft', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('RGT', 'Rgt', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('STOCK', 'Stock', 'double', CreoleTypes::DECIMAL, false, 8);
$tMap->addColumn('OPT_VALUE', 'OptValue', 'string', CreoleTypes::VARCHAR, false, 128);
$tMap->addColumn('PRICE_TYPE', 'PriceType', 'string', CreoleTypes::VARCHAR, false, 6);
$tMap->addColumn('DEPTH', 'Depth', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('OPT_VERSION', 'OptVersion', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('COLOR', 'Color', 'string', CreoleTypes::VARCHAR, false, 128);
$tMap->addColumn('USE_IMAGE_AS_COLOR', 'UseImageAsColor', 'boolean', CreoleTypes::BOOLEAN, false, null);
$tMap->addColumn('OPT_FILTER_ID', 'OptFilterId', 'int', CreoleTypes::INTEGER, false, null);
$tMap->addColumn('USE_PRODUCT', 'UseProduct', 'string', CreoleTypes::VARCHAR, false, 128);
$tMap->addColumn('OLD_PRICE', 'OldPrice', 'double', CreoleTypes::DECIMAL, false, 10);
$tMap->addColumn('MAN_CODE', 'ManCode', 'string', CreoleTypes::VARCHAR, false, 128);
$tMap->addColumn('PUM', 'Pum', 'double', CreoleTypes::DECIMAL, false, 10);
$tMap->addColumn('IS_UPDATED', 'IsUpdated', 'boolean', CreoleTypes::BOOLEAN, false, null);
} // doBuild()
} // ProductOptionsValueMapBuilder

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,776 @@
<?php
/**
* Base class that represents a row from the 'st_product_options_default_value_i18n' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model.om
*/
abstract class BaseProductOptionsDefaultValueI18n extends BaseObject implements Persistent {
protected static $dispatcher = null;
/**
* The value for the id field.
* @var int
*/
protected $id;
/**
* The value for the culture field.
* @var string
*/
protected $culture;
/**
* The value for the value field.
* @var string
*/
protected $value;
/**
* @var ProductOptionsDefaultValue
*/
protected $aProductOptionsDefaultValue;
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
* @var boolean
*/
protected $alreadyInSave = false;
/**
* Flag to prevent endless validation loop, if this object is referenced
* by another object which falls in this transaction.
* @var boolean
*/
protected $alreadyInValidation = false;
/**
* Get the [id] column value.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Get the [culture] column value.
*
* @return string
*/
public function getCulture()
{
return $this->culture;
}
/**
* Get the [value] column value.
*
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* Set the value of [id] column.
*
* @param int $v new value
* @return void
*/
public function setId($v)
{
if ($v !== null && !is_int($v) && is_numeric($v)) {
$v = (int) $v;
}
if ($this->id !== $v) {
$this->id = $v;
$this->modifiedColumns[] = ProductOptionsDefaultValueI18nPeer::ID;
}
if ($this->aProductOptionsDefaultValue !== null && $this->aProductOptionsDefaultValue->getId() !== $v) {
$this->aProductOptionsDefaultValue = null;
}
} // setId()
/**
* Set the value of [culture] column.
*
* @param string $v new value
* @return void
*/
public function setCulture($v)
{
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->culture !== $v) {
$this->culture = $v;
$this->modifiedColumns[] = ProductOptionsDefaultValueI18nPeer::CULTURE;
}
} // setCulture()
/**
* Set the value of [value] column.
*
* @param string $v new value
* @return void
*/
public function setValue($v)
{
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->value !== $v) {
$this->value = $v;
$this->modifiedColumns[] = ProductOptionsDefaultValueI18nPeer::VALUE;
}
} // setValue()
/**
* Hydrates (populates) the object variables with values from the database resultset.
*
* An offset (1-based "start column") is specified so that objects can be hydrated
* with a subset of the columns in the resultset rows. This is needed, for example,
* for results of JOIN queries where the resultset row includes columns from two or
* more tables.
*
* @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos.
* @param int $startcol 1-based offset column which indicates which restultset column to start with.
* @return int next starting column
* @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
*/
public function hydrate(ResultSet $rs, $startcol = 1)
{
try {
if ($this->getDispatcher()->getListeners('ProductOptionsDefaultValueI18n.preHydrate')) {
$event = $this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsDefaultValueI18n.preHydrate', array('resultset' => $rs, 'startcol' => $startcol)));
$startcol = $event['startcol'];
}
$this->id = $rs->getInt($startcol + 0);
$this->culture = $rs->getString($startcol + 1);
$this->value = $rs->getString($startcol + 2);
$this->resetModified();
$this->setNew(false);
if ($this->getDispatcher()->getListeners('ProductOptionsDefaultValueI18n.postHydrate')) {
$event = $this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsDefaultValueI18n.postHydrate', array('resultset' => $rs, 'startcol' => $startcol + 3)));
return $event['startcol'];
}
// FIXME - using NUM_COLUMNS may be clearer.
return $startcol + 3; // 3 = ProductOptionsDefaultValueI18nPeer::NUM_COLUMNS - ProductOptionsDefaultValueI18nPeer::NUM_LAZY_LOAD_COLUMNS).
} catch (Exception $e) {
throw new PropelException("Error populating ProductOptionsDefaultValueI18n object", $e);
}
}
/**
* Removes this object from datastore and sets delete attribute.
*
* @param Connection $con
* @return void
* @throws PropelException
* @see BaseObject::setDeleted()
* @see BaseObject::isDeleted()
*/
public function delete($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("This object has already been deleted.");
}
if ($this->getDispatcher()->getListeners('ProductOptionsDefaultValueI18n.preDelete')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsDefaultValueI18n.preDelete', array('con' => $con)));
}
if (sfMixer::hasCallables('BaseProductOptionsDefaultValueI18n:delete:pre'))
{
foreach (sfMixer::getCallables('BaseProductOptionsDefaultValueI18n:delete:pre') as $callable)
{
$ret = call_user_func($callable, $this, $con);
if ($ret)
{
return;
}
}
}
if ($con === null) {
$con = Propel::getConnection(ProductOptionsDefaultValueI18nPeer::DATABASE_NAME);
}
try {
$con->begin();
ProductOptionsDefaultValueI18nPeer::doDelete($this, $con);
$this->setDeleted(true);
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
if ($this->getDispatcher()->getListeners('ProductOptionsDefaultValueI18n.postDelete')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsDefaultValueI18n.postDelete', array('con' => $con)));
}
if (sfMixer::hasCallables('BaseProductOptionsDefaultValueI18n:delete:post'))
{
foreach (sfMixer::getCallables('BaseProductOptionsDefaultValueI18n:delete:post') as $callable)
{
call_user_func($callable, $this, $con);
}
}
}
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed. This method
* wraps the doSave() worker method in a transaction.
*
* @param Connection $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see doSave()
*/
public function save($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("You cannot save an object that has been deleted.");
}
if (!$this->alreadyInSave) {
if ($this->getDispatcher()->getListeners('ProductOptionsDefaultValueI18n.preSave')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsDefaultValueI18n.preSave', array('con' => $con)));
}
foreach (sfMixer::getCallables('BaseProductOptionsDefaultValueI18n:save:pre') as $callable)
{
$affectedRows = call_user_func($callable, $this, $con);
if (is_int($affectedRows))
{
return $affectedRows;
}
}
}
if ($con === null) {
$con = Propel::getConnection(ProductOptionsDefaultValueI18nPeer::DATABASE_NAME);
}
try {
$con->begin();
$affectedRows = $this->doSave($con);
$con->commit();
if (!$this->alreadyInSave) {
if ($this->getDispatcher()->getListeners('ProductOptionsDefaultValueI18n.postSave')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsDefaultValueI18n.postSave', array('con' => $con)));
}
foreach (sfMixer::getCallables('BaseProductOptionsDefaultValueI18n:save:post') as $callable)
{
call_user_func($callable, $this, $con, $affectedRows);
}
}
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Stores the object in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param Connection $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave($con)
{
$affectedRows = 0; // initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aProductOptionsDefaultValue !== null) {
if ($this->aProductOptionsDefaultValue->isModified() || $this->aProductOptionsDefaultValue->getCurrentProductOptionsDefaultValueI18n()->isModified()) {
$affectedRows += $this->aProductOptionsDefaultValue->save($con);
}
$this->setProductOptionsDefaultValue($this->aProductOptionsDefaultValue);
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = ProductOptionsDefaultValueI18nPeer::doInsert($this, $con);
$affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setNew(false);
} else {
$affectedRows += ProductOptionsDefaultValueI18nPeer::doUpdate($this, $con);
}
$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
} // doSave()
/**
* Array of ValidationFailed objects.
* @var array ValidationFailed[]
*/
protected $validationFailures = array();
/**
* Gets any ValidationFailed objects that resulted from last call to validate().
*
*
* @return array ValidationFailed[]
* @see validate()
*/
public function getValidationFailures()
{
return $this->validationFailures;
}
/**
* Validates the objects modified field values and all objects related to this table.
*
* If $columns is either a column name or an array of column names
* only those columns are validated.
*
* @param mixed $columns Column name or an array of column names.
* @return boolean Whether all columns pass validation.
* @see doValidate()
* @see getValidationFailures()
*/
public function validate($columns = null)
{
$res = $this->doValidate($columns);
if ($res === true) {
$this->validationFailures = array();
return true;
} else {
$this->validationFailures = $res;
return false;
}
}
/**
* This function performs the validation work for complex object models.
*
* In addition to checking the current object, all related objects will
* also be validated. If all pass then <code>true</code> is returned; otherwise
* an aggreagated array of ValidationFailed objects will be returned.
*
* @param array $columns Array of column names to validate.
* @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
*/
protected function doValidate($columns = null)
{
if (!$this->alreadyInValidation) {
$this->alreadyInValidation = true;
$retval = null;
$failureMap = array();
// We call the validate method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aProductOptionsDefaultValue !== null) {
if (!$this->aProductOptionsDefaultValue->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aProductOptionsDefaultValue->getValidationFailures());
}
}
if (($retval = ProductOptionsDefaultValueI18nPeer::doValidate($this, $columns)) !== true) {
$failureMap = array_merge($failureMap, $retval);
}
$this->alreadyInValidation = false;
}
return (!empty($failureMap) ? $failureMap : true);
}
/**
* Retrieves a field from the object by name passed in as a string.
*
* @param string $name name
* @param string $type The type of fieldname the $name is of:
* one of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return mixed Value of field.
*/
public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
{
$pos = ProductOptionsDefaultValueI18nPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
return $this->getByPosition($pos);
}
/**
* Retrieves a field from the object by Position as specified in the xml schema.
* Zero-based.
*
* @param int $pos position in xml schema
* @return mixed Value of field at $pos
*/
public function getByPosition($pos)
{
switch($pos) {
case 0:
return $this->getId();
break;
case 1:
return $this->getCulture();
break;
case 2:
return $this->getValue();
break;
default:
return null;
break;
} // switch()
}
/**
* Exports the object as an array.
*
* You can specify the key type of the array by passing one of the class
* type constants.
*
* @param string $keyType One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return an associative array containing the field names (as keys) and field values
*/
public function toArray($keyType = BasePeer::TYPE_PHPNAME)
{
$keys = ProductOptionsDefaultValueI18nPeer::getFieldNames($keyType);
$result = array(
$keys[0] => $this->getId(),
$keys[1] => $this->getCulture(),
$keys[2] => $this->getValue(),
);
return $result;
}
/**
* Sets a field from the object by name passed in as a string.
*
* @param string $name peer name
* @param mixed $value field value
* @param string $type The type of fieldname the $name is of:
* one of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return void
*/
public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
{
$pos = ProductOptionsDefaultValueI18nPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
return $this->setByPosition($pos, $value);
}
/**
* Sets a field from the object by Position as specified in the xml schema.
* Zero-based.
*
* @param int $pos position in xml schema
* @param mixed $value field value
* @return void
*/
public function setByPosition($pos, $value)
{
switch($pos) {
case 0:
$this->setId($value);
break;
case 1:
$this->setCulture($value);
break;
case 2:
$this->setValue($value);
break;
} // switch()
}
/**
* Populates the object using an array.
*
* This is particularly useful when populating an object from one of the
* request arrays (e.g. $_POST). This method goes through the column
* names, checking to see whether a matching key exists in populated
* array. If so the setByName() method is called for that column.
*
* You can specify the key type of the array by additionally passing one
* of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
* TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
*
* @param array $arr An array to populate the object from.
* @param string $keyType The type of keys the array uses.
* @return void
*/
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
{
$keys = ProductOptionsDefaultValueI18nPeer::getFieldNames($keyType);
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
if (array_key_exists($keys[1], $arr)) $this->setCulture($arr[$keys[1]]);
if (array_key_exists($keys[2], $arr)) $this->setValue($arr[$keys[2]]);
}
/**
* Build a Criteria object containing the values of all modified columns in this object.
*
* @return Criteria The Criteria object containing all modified values.
*/
public function buildCriteria()
{
$criteria = new Criteria(ProductOptionsDefaultValueI18nPeer::DATABASE_NAME);
if ($this->isColumnModified(ProductOptionsDefaultValueI18nPeer::ID)) $criteria->add(ProductOptionsDefaultValueI18nPeer::ID, $this->id);
if ($this->isColumnModified(ProductOptionsDefaultValueI18nPeer::CULTURE)) $criteria->add(ProductOptionsDefaultValueI18nPeer::CULTURE, $this->culture);
if ($this->isColumnModified(ProductOptionsDefaultValueI18nPeer::VALUE)) $criteria->add(ProductOptionsDefaultValueI18nPeer::VALUE, $this->value);
return $criteria;
}
/**
* Builds a Criteria object containing the primary key for this object.
*
* Unlike buildCriteria() this method includes the primary key values regardless
* of whether or not they have been modified.
*
* @return Criteria The Criteria object containing value(s) for primary key(s).
*/
public function buildPkeyCriteria()
{
$criteria = new Criteria(ProductOptionsDefaultValueI18nPeer::DATABASE_NAME);
$criteria->add(ProductOptionsDefaultValueI18nPeer::ID, $this->id);
$criteria->add(ProductOptionsDefaultValueI18nPeer::CULTURE, $this->culture);
return $criteria;
}
/**
* Returns the composite primary key for this object.
* The array elements will be in same order as specified in XML.
* @return array
*/
public function getPrimaryKey()
{
return array($this->getId(), $this->getCulture());
}
/**
* Returns [composite] primary key fields
*
* @param string $keyType
* @return array
*/
public function getPrimaryKeyFields($keyType = BasePeer::TYPE_FIELDNAME)
{
return array(ProductOptionsDefaultValueI18nPeer::translateFieldName('id', BasePeer::TYPE_FIELDNAME, $keyType), ProductOptionsDefaultValueI18nPeer::translateFieldName('culture', BasePeer::TYPE_FIELDNAME, $keyType));
}
/**
* Set the [composite] primary key.
*
* @param array $keys The elements of the composite key (order must match the order in XML file).
* @return void
*/
public function setPrimaryKey($keys)
{
$this->setId($keys[0]);
$this->setCulture($keys[1]);
}
/**
* Sets contents of passed object to values from current object.
*
* If desired, this method can also make copies of all associated (fkey referrers)
* objects.
*
* @param object $copyObj An object of ProductOptionsDefaultValueI18n (or compatible) type.
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
* @throws PropelException
*/
public function copyInto($copyObj, $deepCopy = false)
{
$copyObj->setValue($this->value);
$copyObj->setNew(true);
$copyObj->setId(NULL); // this is a pkey column, so set to default value
$copyObj->setCulture(NULL); // this is a pkey column, so set to default value
}
/**
* Makes a copy of this object that will be inserted as a new row in table when saved.
* It creates a new object filling in the simple attributes, but skipping any primary
* keys that are defined for the table.
*
* If desired, this method can also make copies of all associated (fkey referrers)
* objects.
*
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
* @return ProductOptionsDefaultValueI18n Clone of current object.
* @throws PropelException
*/
public function copy($deepCopy = false)
{
// we use get_class(), because this might be a subclass
$clazz = get_class($this);
$copyObj = new $clazz();
$this->copyInto($copyObj, $deepCopy);
return $copyObj;
}
/**
* Returns a peer instance associated with this om.
*
* @return string Peer class name
*/
public function getPeer()
{
return 'ProductOptionsDefaultValueI18nPeer';
}
/**
* Declares an association between this object and a ProductOptionsDefaultValue object.
*
* @param ProductOptionsDefaultValue $v
* @return void
* @throws PropelException
*/
public function setProductOptionsDefaultValue($v)
{
if ($v === null) {
$this->setId(NULL);
} else {
$this->setId($v->getId());
}
$this->aProductOptionsDefaultValue = $v;
}
/**
* Get the associated ProductOptionsDefaultValue object
*
* @param Connection Optional Connection object.
* @return ProductOptionsDefaultValue The associated ProductOptionsDefaultValue object.
* @throws PropelException
*/
public function getProductOptionsDefaultValue($con = null)
{
if ($this->aProductOptionsDefaultValue === null && ($this->id !== null)) {
// include the related Peer class
$this->aProductOptionsDefaultValue = ProductOptionsDefaultValuePeer::retrieveByPK($this->id, $con);
/* The following can be used instead of the line above to
guarantee the related object contains a reference
to this object, but this level of coupling
may be undesirable in many circumstances.
As it can lead to a db query with many results that may
never be used.
$obj = ProductOptionsDefaultValuePeer::retrieveByPK($this->id, $con);
$obj->addProductOptionsDefaultValues($this);
*/
}
return $this->aProductOptionsDefaultValue;
}
public function getDispatcher()
{
if (null === self::$dispatcher)
{
self::$dispatcher = stEventDispatcher::getInstance();
}
return self::$dispatcher;
}
public function __call($method, $arguments)
{
$event = $this->getDispatcher()->notifyUntil(new sfEvent($this, 'ProductOptionsDefaultValueI18n.' . $method, array('arguments' => $arguments, 'method' => $method)));
if ($event->isProcessed())
{
return $event->getReturnValue();
}
if (!$callable = sfMixer::getCallable('BaseProductOptionsDefaultValueI18n:'.$method))
{
throw new sfException(sprintf('Call to undefined method BaseProductOptionsDefaultValueI18n::%s', $method));
}
array_unshift($arguments, $this);
return call_user_func_array($callable, $arguments);
}
} // BaseProductOptionsDefaultValueI18n

View File

@@ -0,0 +1,834 @@
<?php
/**
* Base static class for performing query and update operations on the 'st_product_options_default_value_i18n' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model.om
*/
abstract class BaseProductOptionsDefaultValueI18nPeer {
/** the default database name for this class */
const DATABASE_NAME = 'propel';
/** the table name for this class */
const TABLE_NAME = 'st_product_options_default_value_i18n';
/** A class that can be returned by this peer. */
const CLASS_DEFAULT = 'plugins.stProductOptionsPlugin.lib.model.ProductOptionsDefaultValueI18n';
/** The total number of columns. */
const NUM_COLUMNS = 3;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
/** the column name for the ID field */
const ID = 'st_product_options_default_value_i18n.ID';
/** the column name for the CULTURE field */
const CULTURE = 'st_product_options_default_value_i18n.CULTURE';
/** the column name for the VALUE field */
const VALUE = 'st_product_options_default_value_i18n.VALUE';
/** The PHP to DB Name Mapping */
private static $phpNameMap = null;
/**
* holds an array of fieldnames
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('Id', 'Culture', 'Value', ),
BasePeer::TYPE_COLNAME => array (ProductOptionsDefaultValueI18nPeer::ID, ProductOptionsDefaultValueI18nPeer::CULTURE, ProductOptionsDefaultValueI18nPeer::VALUE, ),
BasePeer::TYPE_FIELDNAME => array ('id', 'culture', 'value', ),
BasePeer::TYPE_NUM => array (0, 1, 2, )
);
/**
* holds an array of keys for quick access to the fieldnames array
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Culture' => 1, 'Value' => 2, ),
BasePeer::TYPE_COLNAME => array (ProductOptionsDefaultValueI18nPeer::ID => 0, ProductOptionsDefaultValueI18nPeer::CULTURE => 1, ProductOptionsDefaultValueI18nPeer::VALUE => 2, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'culture' => 1, 'value' => 2, ),
BasePeer::TYPE_NUM => array (0, 1, 2, )
);
protected static $hydrateMethod = null;
protected static $postHydrateMethod = null;
public static function setHydrateMethod($callback)
{
self::$hydrateMethod = $callback;
}
public static function setPostHydrateMethod($callback)
{
self::$postHydrateMethod = $callback;
}
/**
* @return MapBuilder the map builder for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getMapBuilder()
{
return BasePeer::getMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsDefaultValueI18nMapBuilder');
}
/**
* Gets a map (hash) of PHP names to DB column names.
*
* @return array The PHP to DB name map for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
*/
public static function getPhpNameMap()
{
if (self::$phpNameMap === null) {
$map = ProductOptionsDefaultValueI18nPeer::getTableMap();
$columns = $map->getColumns();
$nameMap = array();
foreach ($columns as $column) {
$nameMap[$column->getPhpName()] = $column->getColumnName();
}
self::$phpNameMap = $nameMap;
}
return self::$phpNameMap;
}
/**
* Translates a fieldname to another type
*
* @param string $name field name
* @param string $fromType One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @param string $toType One of the class type constants
* @return string translated name of the field.
*/
static public function translateFieldName($name, $fromType, $toType)
{
$toNames = self::getFieldNames($toType);
$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
if ($key === null) {
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
}
return $toNames[$key];
}
/**
* Returns an array of of field names.
*
* @param string $type The type of fieldnames to return:
* One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return array A list of field names
*/
static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
{
if (!array_key_exists($type, self::$fieldNames)) {
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
}
return self::$fieldNames[$type];
}
/**
* Convenience method which changes table.column to alias.column.
*
* Using this method you can maintain SQL abstraction while using column aliases.
* <code>
* $c->addAlias("alias1", TablePeer::TABLE_NAME);
* $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
* </code>
* @param string $alias The alias for the current table.
* @param string $column The column name for current table. (i.e. ProductOptionsDefaultValueI18nPeer::COLUMN_NAME).
* @return string
*/
public static function alias($alias, $column)
{
return str_replace(ProductOptionsDefaultValueI18nPeer::TABLE_NAME.'.', $alias.'.', $column);
}
/**
* Add all the columns needed to create a new object.
*
* Note: any columns that were marked with lazyLoad="true" in the
* XML schema will not be added to the select list and only loaded
* on demand.
*
* @param criteria object containing the columns to add.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function addSelectColumns(Criteria $criteria)
{
$criteria->addSelectColumn(ProductOptionsDefaultValueI18nPeer::ID);
$criteria->addSelectColumn(ProductOptionsDefaultValueI18nPeer::CULTURE);
$criteria->addSelectColumn(ProductOptionsDefaultValueI18nPeer::VALUE);
if (stEventDispatcher::getInstance()->getListeners('ProductOptionsDefaultValueI18nPeer.postAddSelectColumns')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'ProductOptionsDefaultValueI18nPeer.postAddSelectColumns'));
}
}
const COUNT = 'COUNT(st_product_options_default_value_i18n.ID)';
const COUNT_DISTINCT = 'COUNT(DISTINCT st_product_options_default_value_i18n.ID)';
/**
* Returns the number of rows matching criteria.
*
* @param Criteria $criteria
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCount(Criteria $criteria, $distinct = false, $con = null)
{
// we're going to modify criteria, so copy it first
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsDefaultValueI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsDefaultValueI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$rs = ProductOptionsDefaultValueI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Method to select one object from the DB.
*
* @param Criteria $criteria object used to create the SELECT statement.
* @param Connection $con
* @return ProductOptionsDefaultValueI18n
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectOne(Criteria $criteria, $con = null)
{
$critcopy = clone $criteria;
$critcopy->setLimit(1);
$objects = ProductOptionsDefaultValueI18nPeer::doSelect($critcopy, $con);
if ($objects) {
return $objects[0];
}
return null;
}
/**
* Method to do selects.
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con
* @return ProductOptionsDefaultValueI18n[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelect(Criteria $criteria, $con = null)
{
return ProductOptionsDefaultValueI18nPeer::populateObjects(ProductOptionsDefaultValueI18nPeer::doSelectRS($criteria, $con));
}
/**
* Prepares the Criteria object and uses the parent doSelect()
* method to get a ResultSet.
*
* Use this method directly if you want to just get the resultset
* (instead of an array of objects).
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con the connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return ResultSet The resultset object with numerically-indexed fields.
* @see BasePeer::doSelect()
*/
public static function doSelectRS(Criteria $criteria, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if (!$criteria->getSelectColumns()) {
$criteria = clone $criteria;
ProductOptionsDefaultValueI18nPeer::addSelectColumns($criteria);
}
if (stEventDispatcher::getInstance()->getListeners('BasePeer.preDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'BasePeer.preDoSelectRs'));
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
// BasePeer returns a Creole ResultSet, set to return
// rows indexed numerically.
$rs = BasePeer::doSelect($criteria, $con);
if (stEventDispatcher::getInstance()->getListeners('BasePeer.postDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($rs, 'BasePeer.postDoSelectRs'));
}
return $rs;
}
/**
* The returned array will contain objects of the default type or
* objects that inherit from the default.
*
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function populateObjects(ResultSet $rs)
{
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
// set the class once to avoid overhead in the loop
$cls = ProductOptionsDefaultValueI18nPeer::getOMClass();
$cls = Propel::import($cls);
// populate the object(s)
while($rs->next()) {
$obj = new $cls();
$obj->hydrate($rs);
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj) : $obj;
}
return $results;
}
/**
* Returns the number of rows matching criteria, joining the related ProductOptionsDefaultValue table
*
* @param Criteria $c
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCountJoinProductOptionsDefaultValue(Criteria $criteria, $distinct = false, $con = null)
{
// we're going to modify criteria, so copy it first
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsDefaultValueI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsDefaultValueI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$criteria->addJoin(ProductOptionsDefaultValueI18nPeer::ID, ProductOptionsDefaultValuePeer::ID);
$rs = ProductOptionsDefaultValueI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Selects a collection of ProductOptionsDefaultValueI18n objects pre-filled with their ProductOptionsDefaultValue objects.
*
* @return ProductOptionsDefaultValueI18n[] Array of ProductOptionsDefaultValueI18n objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinProductOptionsDefaultValue(Criteria $c, $con = null)
{
$c = clone $c;
// Set the correct dbName if it has not been overridden
if ($c->getDbName() == Propel::getDefaultDB()) {
$c->setDbName(self::DATABASE_NAME);
}
ProductOptionsDefaultValueI18nPeer::addSelectColumns($c);
ProductOptionsDefaultValuePeer::addSelectColumns($c);
$c->addJoin(ProductOptionsDefaultValueI18nPeer::ID, ProductOptionsDefaultValuePeer::ID);
$rs = ProductOptionsDefaultValueI18nPeer::doSelectRs($c, $con);
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
while($rs->next()) {
$obj1 = new ProductOptionsDefaultValueI18n();
$startcol = $obj1->hydrate($rs);
if ($obj1->getId())
{
$obj2 = new ProductOptionsDefaultValue();
$obj2->hydrate($rs, $startcol);
$obj2->addProductOptionsDefaultValueI18n($obj1);
}
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj1) : $obj1;;
}
return $results;
}
/**
* Returns the number of rows matching criteria, joining all related tables
*
* @param Criteria $c
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCountJoinAll(Criteria $criteria, $distinct = false, $con = null)
{
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsDefaultValueI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsDefaultValueI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$criteria->addJoin(ProductOptionsDefaultValueI18nPeer::ID, ProductOptionsDefaultValuePeer::ID);
$rs = ProductOptionsDefaultValueI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Selects a collection of ProductOptionsDefaultValueI18n objects pre-filled with all related objects.
*
* @return ProductOptionsDefaultValueI18n[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinAll(Criteria $c, $con = null)
{
$c = clone $c;
// Set the correct dbName if it has not been overridden
if ($c->getDbName() == Propel::getDefaultDB()) {
$c->setDbName(self::DATABASE_NAME);
}
ProductOptionsDefaultValueI18nPeer::addSelectColumns($c);
$startcol2 = (ProductOptionsDefaultValueI18nPeer::NUM_COLUMNS - ProductOptionsDefaultValueI18nPeer::NUM_LAZY_LOAD_COLUMNS) + 1;
ProductOptionsDefaultValuePeer::addSelectColumns($c);
$startcol3 = $startcol2 + ProductOptionsDefaultValuePeer::NUM_COLUMNS;
$c->addJoin(ProductOptionsDefaultValueI18nPeer::ID, ProductOptionsDefaultValuePeer::ID);
$rs = BasePeer::doSelect($c, $con);
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
while($rs->next()) {
$omClass = ProductOptionsDefaultValueI18nPeer::getOMClass();
$cls = Propel::import($omClass);
$obj1 = new $cls();
$obj1->hydrate($rs);
// Add objects for joined ProductOptionsDefaultValue rows
$omClass = ProductOptionsDefaultValuePeer::getOMClass();
$cls = Propel::import($omClass);
$obj2 = new $cls();
$obj2->hydrate($rs, $startcol2);
$newObject = true;
for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
$temp_obj1 = $results[$j];
$temp_obj2 = $temp_obj1->getProductOptionsDefaultValue(); // CHECKME
if (null !== $temp_obj2 && $temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
$newObject = false;
$temp_obj2->addProductOptionsDefaultValueI18n($obj1); // CHECKME
break;
}
}
if ($newObject) {
$obj2->initProductOptionsDefaultValueI18ns();
$obj2->addProductOptionsDefaultValueI18n($obj1);
}
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj1) : $obj1;
}
return $results;
}
/**
* Returns the TableMap related to this peer.
* This method is not needed for general use but a specific application could have a need.
* @return TableMap
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getTableMap()
{
return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
}
/**
* The class that the Peer will make instances of.
*
* This uses a dot-path notation which is tranalted into a path
* relative to a location on the PHP include_path.
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
*
* @return string path.to.ClassName
*/
public static function getOMClass()
{
return ProductOptionsDefaultValueI18nPeer::CLASS_DEFAULT;
}
/**
* Method perform an INSERT on the database, given a ProductOptionsDefaultValueI18n or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsDefaultValueI18n object containing data that is used to create the INSERT statement.
* @param Connection $con the connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsDefaultValueI18nPeer:doInsert:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsDefaultValueI18nPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} else {
$criteria = $values->buildCriteria(); // build Criteria from ProductOptionsDefaultValueI18n object
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->begin();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch(PropelException $e) {
$con->rollback();
throw $e;
}
foreach (sfMixer::getCallables('BaseProductOptionsDefaultValueI18nPeer:doInsert:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsDefaultValueI18nPeer', $values, $con, $pk);
}
return $pk;
}
/**
* Method perform an UPDATE on the database, given a ProductOptionsDefaultValueI18n or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsDefaultValueI18n object containing data that is used to create the UPDATE statement.
* @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
* @return int The number of affected rows (if supported by underlying database driver).
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doUpdate($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsDefaultValueI18nPeer:doUpdate:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsDefaultValueI18nPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$selectCriteria = new Criteria(self::DATABASE_NAME);
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
$comparison = $criteria->getComparison(ProductOptionsDefaultValueI18nPeer::ID);
$selectCriteria->add(ProductOptionsDefaultValueI18nPeer::ID, $criteria->remove(ProductOptionsDefaultValueI18nPeer::ID), $comparison);
$comparison = $criteria->getComparison(ProductOptionsDefaultValueI18nPeer::CULTURE);
$selectCriteria->add(ProductOptionsDefaultValueI18nPeer::CULTURE, $criteria->remove(ProductOptionsDefaultValueI18nPeer::CULTURE), $comparison);
} else { // $values is ProductOptionsDefaultValueI18n object
$criteria = $values->buildCriteria(); // gets full criteria
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
}
// set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
foreach (sfMixer::getCallables('BaseProductOptionsDefaultValueI18nPeer:doUpdate:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsDefaultValueI18nPeer', $values, $con, $ret);
}
return $ret;
}
/**
* Method to DELETE all rows from the st_product_options_default_value_i18n table.
*
* @return int The number of affected rows (if supported by underlying database driver).
*/
public static function doDeleteAll($con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += BasePeer::doDeleteAll(ProductOptionsDefaultValueI18nPeer::TABLE_NAME, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Method perform a DELETE on the database, given a ProductOptionsDefaultValueI18n or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ProductOptionsDefaultValueI18n object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param Connection $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doDelete($values, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(ProductOptionsDefaultValueI18nPeer::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} elseif ($values instanceof ProductOptionsDefaultValueI18n) {
$criteria = $values->buildPkeyCriteria();
} else {
// it must be the primary key
$criteria = new Criteria(self::DATABASE_NAME);
// primary key is composite; we therefore, expect
// the primary key passed to be an array of pkey
// values
if(count($values) == count($values, COUNT_RECURSIVE))
{
// array is not multi-dimensional
$values = array($values);
}
$vals = array();
foreach($values as $value)
{
$vals[0][] = $value[0];
$vals[1][] = $value[1];
}
$criteria->add(ProductOptionsDefaultValueI18nPeer::ID, $vals[0], Criteria::IN);
$criteria->add(ProductOptionsDefaultValueI18nPeer::CULTURE, $vals[1], Criteria::IN);
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += BasePeer::doDelete($criteria, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Validates all modified columns of given ProductOptionsDefaultValueI18n object.
* If parameter $columns is either a single column name or an array of column names
* than only those columns are validated.
*
* NOTICE: This does not apply to primary or foreign keys for now.
*
* @param ProductOptionsDefaultValueI18n $obj The object to validate.
* @param mixed $cols Column name or array of column names.
*
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
*/
public static function doValidate(ProductOptionsDefaultValueI18n $obj, $cols = null)
{
$columns = array();
if ($cols) {
$dbMap = Propel::getDatabaseMap(ProductOptionsDefaultValueI18nPeer::DATABASE_NAME);
$tableMap = $dbMap->getTable(ProductOptionsDefaultValueI18nPeer::TABLE_NAME);
if (! is_array($cols)) {
$cols = array($cols);
}
foreach($cols as $colName) {
if ($tableMap->containsColumn($colName)) {
$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
$columns[$colName] = $obj->$get();
}
}
} else {
}
$res = BasePeer::doValidate(ProductOptionsDefaultValueI18nPeer::DATABASE_NAME, ProductOptionsDefaultValueI18nPeer::TABLE_NAME, $columns);
if ($res !== true) {
$request = sfContext::getInstance()->getRequest();
foreach ($res as $failed) {
$col = ProductOptionsDefaultValueI18nPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
$request->setError($col, $failed->getMessage());
}
}
return $res;
}
/**
* Retrieve object using using composite pkey values.
* @param int $id
@param string $culture
* @param Connection $con
* @return ProductOptionsDefaultValueI18n
*/
public static function retrieveByPK( $id, $culture, $con = null) {
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$criteria = new Criteria();
$criteria->add(ProductOptionsDefaultValueI18nPeer::ID, $id);
$criteria->add(ProductOptionsDefaultValueI18nPeer::CULTURE, $culture);
$v = ProductOptionsDefaultValueI18nPeer::doSelect($criteria, $con);
return !empty($v) ? $v[0] : null;
}
} // BaseProductOptionsDefaultValueI18nPeer
// static code to register the map builder for this Peer with the main Propel class
if (Propel::isInit()) {
// the MapBuilder classes register themselves with Propel during initialization
// so we need to load them here.
try {
BaseProductOptionsDefaultValueI18nPeer::getMapBuilder();
} catch (Exception $e) {
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
}
} else {
// even if Propel is not yet initialized, the map builder class can be registered
// now and then it will be loaded when Propel initializes.
Propel::registerMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsDefaultValueI18nMapBuilder');
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,827 @@
<?php
/**
* Base class that represents a row from the 'st_product_options_field_i18n' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model.om
*/
abstract class BaseProductOptionsFieldI18n extends BaseObject implements Persistent {
protected static $dispatcher = null;
/**
* The value for the id field.
* @var int
*/
protected $id;
/**
* The value for the culture field.
* @var string
*/
protected $culture;
/**
* The value for the name field.
* @var string
*/
protected $name;
/**
* The value for the default_value field.
* @var string
*/
protected $default_value;
/**
* @var ProductOptionsField
*/
protected $aProductOptionsField;
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
* @var boolean
*/
protected $alreadyInSave = false;
/**
* Flag to prevent endless validation loop, if this object is referenced
* by another object which falls in this transaction.
* @var boolean
*/
protected $alreadyInValidation = false;
/**
* Get the [id] column value.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Get the [culture] column value.
*
* @return string
*/
public function getCulture()
{
return $this->culture;
}
/**
* Get the [name] column value.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get the [default_value] column value.
*
* @return string
*/
public function getDefaultValue()
{
return $this->default_value;
}
/**
* Set the value of [id] column.
*
* @param int $v new value
* @return void
*/
public function setId($v)
{
if ($v !== null && !is_int($v) && is_numeric($v)) {
$v = (int) $v;
}
if ($this->id !== $v) {
$this->id = $v;
$this->modifiedColumns[] = ProductOptionsFieldI18nPeer::ID;
}
if ($this->aProductOptionsField !== null && $this->aProductOptionsField->getId() !== $v) {
$this->aProductOptionsField = null;
}
} // setId()
/**
* Set the value of [culture] column.
*
* @param string $v new value
* @return void
*/
public function setCulture($v)
{
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->culture !== $v) {
$this->culture = $v;
$this->modifiedColumns[] = ProductOptionsFieldI18nPeer::CULTURE;
}
} // setCulture()
/**
* Set the value of [name] column.
*
* @param string $v new value
* @return void
*/
public function setName($v)
{
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->name !== $v) {
$this->name = $v;
$this->modifiedColumns[] = ProductOptionsFieldI18nPeer::NAME;
}
} // setName()
/**
* Set the value of [default_value] column.
*
* @param string $v new value
* @return void
*/
public function setDefaultValue($v)
{
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->default_value !== $v) {
$this->default_value = $v;
$this->modifiedColumns[] = ProductOptionsFieldI18nPeer::DEFAULT_VALUE;
}
} // setDefaultValue()
/**
* Hydrates (populates) the object variables with values from the database resultset.
*
* An offset (1-based "start column") is specified so that objects can be hydrated
* with a subset of the columns in the resultset rows. This is needed, for example,
* for results of JOIN queries where the resultset row includes columns from two or
* more tables.
*
* @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos.
* @param int $startcol 1-based offset column which indicates which restultset column to start with.
* @return int next starting column
* @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
*/
public function hydrate(ResultSet $rs, $startcol = 1)
{
try {
if ($this->getDispatcher()->getListeners('ProductOptionsFieldI18n.preHydrate')) {
$event = $this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFieldI18n.preHydrate', array('resultset' => $rs, 'startcol' => $startcol)));
$startcol = $event['startcol'];
}
$this->id = $rs->getInt($startcol + 0);
$this->culture = $rs->getString($startcol + 1);
$this->name = $rs->getString($startcol + 2);
$this->default_value = $rs->getString($startcol + 3);
$this->resetModified();
$this->setNew(false);
if ($this->getDispatcher()->getListeners('ProductOptionsFieldI18n.postHydrate')) {
$event = $this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFieldI18n.postHydrate', array('resultset' => $rs, 'startcol' => $startcol + 4)));
return $event['startcol'];
}
// FIXME - using NUM_COLUMNS may be clearer.
return $startcol + 4; // 4 = ProductOptionsFieldI18nPeer::NUM_COLUMNS - ProductOptionsFieldI18nPeer::NUM_LAZY_LOAD_COLUMNS).
} catch (Exception $e) {
throw new PropelException("Error populating ProductOptionsFieldI18n object", $e);
}
}
/**
* Removes this object from datastore and sets delete attribute.
*
* @param Connection $con
* @return void
* @throws PropelException
* @see BaseObject::setDeleted()
* @see BaseObject::isDeleted()
*/
public function delete($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("This object has already been deleted.");
}
if ($this->getDispatcher()->getListeners('ProductOptionsFieldI18n.preDelete')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFieldI18n.preDelete', array('con' => $con)));
}
if (sfMixer::hasCallables('BaseProductOptionsFieldI18n:delete:pre'))
{
foreach (sfMixer::getCallables('BaseProductOptionsFieldI18n:delete:pre') as $callable)
{
$ret = call_user_func($callable, $this, $con);
if ($ret)
{
return;
}
}
}
if ($con === null) {
$con = Propel::getConnection(ProductOptionsFieldI18nPeer::DATABASE_NAME);
}
try {
$con->begin();
ProductOptionsFieldI18nPeer::doDelete($this, $con);
$this->setDeleted(true);
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
if ($this->getDispatcher()->getListeners('ProductOptionsFieldI18n.postDelete')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFieldI18n.postDelete', array('con' => $con)));
}
if (sfMixer::hasCallables('BaseProductOptionsFieldI18n:delete:post'))
{
foreach (sfMixer::getCallables('BaseProductOptionsFieldI18n:delete:post') as $callable)
{
call_user_func($callable, $this, $con);
}
}
}
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed. This method
* wraps the doSave() worker method in a transaction.
*
* @param Connection $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see doSave()
*/
public function save($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("You cannot save an object that has been deleted.");
}
if (!$this->alreadyInSave) {
if ($this->getDispatcher()->getListeners('ProductOptionsFieldI18n.preSave')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFieldI18n.preSave', array('con' => $con)));
}
foreach (sfMixer::getCallables('BaseProductOptionsFieldI18n:save:pre') as $callable)
{
$affectedRows = call_user_func($callable, $this, $con);
if (is_int($affectedRows))
{
return $affectedRows;
}
}
}
if ($con === null) {
$con = Propel::getConnection(ProductOptionsFieldI18nPeer::DATABASE_NAME);
}
try {
$con->begin();
$affectedRows = $this->doSave($con);
$con->commit();
if (!$this->alreadyInSave) {
if ($this->getDispatcher()->getListeners('ProductOptionsFieldI18n.postSave')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFieldI18n.postSave', array('con' => $con)));
}
foreach (sfMixer::getCallables('BaseProductOptionsFieldI18n:save:post') as $callable)
{
call_user_func($callable, $this, $con, $affectedRows);
}
}
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Stores the object in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param Connection $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave($con)
{
$affectedRows = 0; // initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aProductOptionsField !== null) {
if ($this->aProductOptionsField->isModified() || $this->aProductOptionsField->getCurrentProductOptionsFieldI18n()->isModified()) {
$affectedRows += $this->aProductOptionsField->save($con);
}
$this->setProductOptionsField($this->aProductOptionsField);
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = ProductOptionsFieldI18nPeer::doInsert($this, $con);
$affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setNew(false);
} else {
$affectedRows += ProductOptionsFieldI18nPeer::doUpdate($this, $con);
}
$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
} // doSave()
/**
* Array of ValidationFailed objects.
* @var array ValidationFailed[]
*/
protected $validationFailures = array();
/**
* Gets any ValidationFailed objects that resulted from last call to validate().
*
*
* @return array ValidationFailed[]
* @see validate()
*/
public function getValidationFailures()
{
return $this->validationFailures;
}
/**
* Validates the objects modified field values and all objects related to this table.
*
* If $columns is either a column name or an array of column names
* only those columns are validated.
*
* @param mixed $columns Column name or an array of column names.
* @return boolean Whether all columns pass validation.
* @see doValidate()
* @see getValidationFailures()
*/
public function validate($columns = null)
{
$res = $this->doValidate($columns);
if ($res === true) {
$this->validationFailures = array();
return true;
} else {
$this->validationFailures = $res;
return false;
}
}
/**
* This function performs the validation work for complex object models.
*
* In addition to checking the current object, all related objects will
* also be validated. If all pass then <code>true</code> is returned; otherwise
* an aggreagated array of ValidationFailed objects will be returned.
*
* @param array $columns Array of column names to validate.
* @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
*/
protected function doValidate($columns = null)
{
if (!$this->alreadyInValidation) {
$this->alreadyInValidation = true;
$retval = null;
$failureMap = array();
// We call the validate method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aProductOptionsField !== null) {
if (!$this->aProductOptionsField->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aProductOptionsField->getValidationFailures());
}
}
if (($retval = ProductOptionsFieldI18nPeer::doValidate($this, $columns)) !== true) {
$failureMap = array_merge($failureMap, $retval);
}
$this->alreadyInValidation = false;
}
return (!empty($failureMap) ? $failureMap : true);
}
/**
* Retrieves a field from the object by name passed in as a string.
*
* @param string $name name
* @param string $type The type of fieldname the $name is of:
* one of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return mixed Value of field.
*/
public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
{
$pos = ProductOptionsFieldI18nPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
return $this->getByPosition($pos);
}
/**
* Retrieves a field from the object by Position as specified in the xml schema.
* Zero-based.
*
* @param int $pos position in xml schema
* @return mixed Value of field at $pos
*/
public function getByPosition($pos)
{
switch($pos) {
case 0:
return $this->getId();
break;
case 1:
return $this->getCulture();
break;
case 2:
return $this->getName();
break;
case 3:
return $this->getDefaultValue();
break;
default:
return null;
break;
} // switch()
}
/**
* Exports the object as an array.
*
* You can specify the key type of the array by passing one of the class
* type constants.
*
* @param string $keyType One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return an associative array containing the field names (as keys) and field values
*/
public function toArray($keyType = BasePeer::TYPE_PHPNAME)
{
$keys = ProductOptionsFieldI18nPeer::getFieldNames($keyType);
$result = array(
$keys[0] => $this->getId(),
$keys[1] => $this->getCulture(),
$keys[2] => $this->getName(),
$keys[3] => $this->getDefaultValue(),
);
return $result;
}
/**
* Sets a field from the object by name passed in as a string.
*
* @param string $name peer name
* @param mixed $value field value
* @param string $type The type of fieldname the $name is of:
* one of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return void
*/
public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
{
$pos = ProductOptionsFieldI18nPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
return $this->setByPosition($pos, $value);
}
/**
* Sets a field from the object by Position as specified in the xml schema.
* Zero-based.
*
* @param int $pos position in xml schema
* @param mixed $value field value
* @return void
*/
public function setByPosition($pos, $value)
{
switch($pos) {
case 0:
$this->setId($value);
break;
case 1:
$this->setCulture($value);
break;
case 2:
$this->setName($value);
break;
case 3:
$this->setDefaultValue($value);
break;
} // switch()
}
/**
* Populates the object using an array.
*
* This is particularly useful when populating an object from one of the
* request arrays (e.g. $_POST). This method goes through the column
* names, checking to see whether a matching key exists in populated
* array. If so the setByName() method is called for that column.
*
* You can specify the key type of the array by additionally passing one
* of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
* TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
*
* @param array $arr An array to populate the object from.
* @param string $keyType The type of keys the array uses.
* @return void
*/
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
{
$keys = ProductOptionsFieldI18nPeer::getFieldNames($keyType);
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
if (array_key_exists($keys[1], $arr)) $this->setCulture($arr[$keys[1]]);
if (array_key_exists($keys[2], $arr)) $this->setName($arr[$keys[2]]);
if (array_key_exists($keys[3], $arr)) $this->setDefaultValue($arr[$keys[3]]);
}
/**
* Build a Criteria object containing the values of all modified columns in this object.
*
* @return Criteria The Criteria object containing all modified values.
*/
public function buildCriteria()
{
$criteria = new Criteria(ProductOptionsFieldI18nPeer::DATABASE_NAME);
if ($this->isColumnModified(ProductOptionsFieldI18nPeer::ID)) $criteria->add(ProductOptionsFieldI18nPeer::ID, $this->id);
if ($this->isColumnModified(ProductOptionsFieldI18nPeer::CULTURE)) $criteria->add(ProductOptionsFieldI18nPeer::CULTURE, $this->culture);
if ($this->isColumnModified(ProductOptionsFieldI18nPeer::NAME)) $criteria->add(ProductOptionsFieldI18nPeer::NAME, $this->name);
if ($this->isColumnModified(ProductOptionsFieldI18nPeer::DEFAULT_VALUE)) $criteria->add(ProductOptionsFieldI18nPeer::DEFAULT_VALUE, $this->default_value);
return $criteria;
}
/**
* Builds a Criteria object containing the primary key for this object.
*
* Unlike buildCriteria() this method includes the primary key values regardless
* of whether or not they have been modified.
*
* @return Criteria The Criteria object containing value(s) for primary key(s).
*/
public function buildPkeyCriteria()
{
$criteria = new Criteria(ProductOptionsFieldI18nPeer::DATABASE_NAME);
$criteria->add(ProductOptionsFieldI18nPeer::ID, $this->id);
$criteria->add(ProductOptionsFieldI18nPeer::CULTURE, $this->culture);
return $criteria;
}
/**
* Returns the composite primary key for this object.
* The array elements will be in same order as specified in XML.
* @return array
*/
public function getPrimaryKey()
{
return array($this->getId(), $this->getCulture());
}
/**
* Returns [composite] primary key fields
*
* @param string $keyType
* @return array
*/
public function getPrimaryKeyFields($keyType = BasePeer::TYPE_FIELDNAME)
{
return array(ProductOptionsFieldI18nPeer::translateFieldName('id', BasePeer::TYPE_FIELDNAME, $keyType), ProductOptionsFieldI18nPeer::translateFieldName('culture', BasePeer::TYPE_FIELDNAME, $keyType));
}
/**
* Set the [composite] primary key.
*
* @param array $keys The elements of the composite key (order must match the order in XML file).
* @return void
*/
public function setPrimaryKey($keys)
{
$this->setId($keys[0]);
$this->setCulture($keys[1]);
}
/**
* Sets contents of passed object to values from current object.
*
* If desired, this method can also make copies of all associated (fkey referrers)
* objects.
*
* @param object $copyObj An object of ProductOptionsFieldI18n (or compatible) type.
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
* @throws PropelException
*/
public function copyInto($copyObj, $deepCopy = false)
{
$copyObj->setName($this->name);
$copyObj->setDefaultValue($this->default_value);
$copyObj->setNew(true);
$copyObj->setId(NULL); // this is a pkey column, so set to default value
$copyObj->setCulture(NULL); // this is a pkey column, so set to default value
}
/**
* Makes a copy of this object that will be inserted as a new row in table when saved.
* It creates a new object filling in the simple attributes, but skipping any primary
* keys that are defined for the table.
*
* If desired, this method can also make copies of all associated (fkey referrers)
* objects.
*
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
* @return ProductOptionsFieldI18n Clone of current object.
* @throws PropelException
*/
public function copy($deepCopy = false)
{
// we use get_class(), because this might be a subclass
$clazz = get_class($this);
$copyObj = new $clazz();
$this->copyInto($copyObj, $deepCopy);
return $copyObj;
}
/**
* Returns a peer instance associated with this om.
*
* @return string Peer class name
*/
public function getPeer()
{
return 'ProductOptionsFieldI18nPeer';
}
/**
* Declares an association between this object and a ProductOptionsField object.
*
* @param ProductOptionsField $v
* @return void
* @throws PropelException
*/
public function setProductOptionsField($v)
{
if ($v === null) {
$this->setId(NULL);
} else {
$this->setId($v->getId());
}
$this->aProductOptionsField = $v;
}
/**
* Get the associated ProductOptionsField object
*
* @param Connection Optional Connection object.
* @return ProductOptionsField The associated ProductOptionsField object.
* @throws PropelException
*/
public function getProductOptionsField($con = null)
{
if ($this->aProductOptionsField === null && ($this->id !== null)) {
// include the related Peer class
$this->aProductOptionsField = ProductOptionsFieldPeer::retrieveByPK($this->id, $con);
/* The following can be used instead of the line above to
guarantee the related object contains a reference
to this object, but this level of coupling
may be undesirable in many circumstances.
As it can lead to a db query with many results that may
never be used.
$obj = ProductOptionsFieldPeer::retrieveByPK($this->id, $con);
$obj->addProductOptionsFields($this);
*/
}
return $this->aProductOptionsField;
}
public function getDispatcher()
{
if (null === self::$dispatcher)
{
self::$dispatcher = stEventDispatcher::getInstance();
}
return self::$dispatcher;
}
public function __call($method, $arguments)
{
$event = $this->getDispatcher()->notifyUntil(new sfEvent($this, 'ProductOptionsFieldI18n.' . $method, array('arguments' => $arguments, 'method' => $method)));
if ($event->isProcessed())
{
return $event->getReturnValue();
}
if (!$callable = sfMixer::getCallable('BaseProductOptionsFieldI18n:'.$method))
{
throw new sfException(sprintf('Call to undefined method BaseProductOptionsFieldI18n::%s', $method));
}
array_unshift($arguments, $this);
return call_user_func_array($callable, $arguments);
}
} // BaseProductOptionsFieldI18n

View File

@@ -0,0 +1,839 @@
<?php
/**
* Base static class for performing query and update operations on the 'st_product_options_field_i18n' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model.om
*/
abstract class BaseProductOptionsFieldI18nPeer {
/** the default database name for this class */
const DATABASE_NAME = 'propel';
/** the table name for this class */
const TABLE_NAME = 'st_product_options_field_i18n';
/** A class that can be returned by this peer. */
const CLASS_DEFAULT = 'plugins.stProductOptionsPlugin.lib.model.ProductOptionsFieldI18n';
/** The total number of columns. */
const NUM_COLUMNS = 4;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
/** the column name for the ID field */
const ID = 'st_product_options_field_i18n.ID';
/** the column name for the CULTURE field */
const CULTURE = 'st_product_options_field_i18n.CULTURE';
/** the column name for the NAME field */
const NAME = 'st_product_options_field_i18n.NAME';
/** the column name for the DEFAULT_VALUE field */
const DEFAULT_VALUE = 'st_product_options_field_i18n.DEFAULT_VALUE';
/** The PHP to DB Name Mapping */
private static $phpNameMap = null;
/**
* holds an array of fieldnames
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('Id', 'Culture', 'Name', 'DefaultValue', ),
BasePeer::TYPE_COLNAME => array (ProductOptionsFieldI18nPeer::ID, ProductOptionsFieldI18nPeer::CULTURE, ProductOptionsFieldI18nPeer::NAME, ProductOptionsFieldI18nPeer::DEFAULT_VALUE, ),
BasePeer::TYPE_FIELDNAME => array ('id', 'culture', 'name', 'default_value', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
);
/**
* holds an array of keys for quick access to the fieldnames array
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Culture' => 1, 'Name' => 2, 'DefaultValue' => 3, ),
BasePeer::TYPE_COLNAME => array (ProductOptionsFieldI18nPeer::ID => 0, ProductOptionsFieldI18nPeer::CULTURE => 1, ProductOptionsFieldI18nPeer::NAME => 2, ProductOptionsFieldI18nPeer::DEFAULT_VALUE => 3, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'culture' => 1, 'name' => 2, 'default_value' => 3, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
);
protected static $hydrateMethod = null;
protected static $postHydrateMethod = null;
public static function setHydrateMethod($callback)
{
self::$hydrateMethod = $callback;
}
public static function setPostHydrateMethod($callback)
{
self::$postHydrateMethod = $callback;
}
/**
* @return MapBuilder the map builder for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getMapBuilder()
{
return BasePeer::getMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsFieldI18nMapBuilder');
}
/**
* Gets a map (hash) of PHP names to DB column names.
*
* @return array The PHP to DB name map for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
*/
public static function getPhpNameMap()
{
if (self::$phpNameMap === null) {
$map = ProductOptionsFieldI18nPeer::getTableMap();
$columns = $map->getColumns();
$nameMap = array();
foreach ($columns as $column) {
$nameMap[$column->getPhpName()] = $column->getColumnName();
}
self::$phpNameMap = $nameMap;
}
return self::$phpNameMap;
}
/**
* Translates a fieldname to another type
*
* @param string $name field name
* @param string $fromType One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @param string $toType One of the class type constants
* @return string translated name of the field.
*/
static public function translateFieldName($name, $fromType, $toType)
{
$toNames = self::getFieldNames($toType);
$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
if ($key === null) {
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
}
return $toNames[$key];
}
/**
* Returns an array of of field names.
*
* @param string $type The type of fieldnames to return:
* One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return array A list of field names
*/
static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
{
if (!array_key_exists($type, self::$fieldNames)) {
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
}
return self::$fieldNames[$type];
}
/**
* Convenience method which changes table.column to alias.column.
*
* Using this method you can maintain SQL abstraction while using column aliases.
* <code>
* $c->addAlias("alias1", TablePeer::TABLE_NAME);
* $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
* </code>
* @param string $alias The alias for the current table.
* @param string $column The column name for current table. (i.e. ProductOptionsFieldI18nPeer::COLUMN_NAME).
* @return string
*/
public static function alias($alias, $column)
{
return str_replace(ProductOptionsFieldI18nPeer::TABLE_NAME.'.', $alias.'.', $column);
}
/**
* Add all the columns needed to create a new object.
*
* Note: any columns that were marked with lazyLoad="true" in the
* XML schema will not be added to the select list and only loaded
* on demand.
*
* @param criteria object containing the columns to add.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function addSelectColumns(Criteria $criteria)
{
$criteria->addSelectColumn(ProductOptionsFieldI18nPeer::ID);
$criteria->addSelectColumn(ProductOptionsFieldI18nPeer::CULTURE);
$criteria->addSelectColumn(ProductOptionsFieldI18nPeer::NAME);
$criteria->addSelectColumn(ProductOptionsFieldI18nPeer::DEFAULT_VALUE);
if (stEventDispatcher::getInstance()->getListeners('ProductOptionsFieldI18nPeer.postAddSelectColumns')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'ProductOptionsFieldI18nPeer.postAddSelectColumns'));
}
}
const COUNT = 'COUNT(st_product_options_field_i18n.ID)';
const COUNT_DISTINCT = 'COUNT(DISTINCT st_product_options_field_i18n.ID)';
/**
* Returns the number of rows matching criteria.
*
* @param Criteria $criteria
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCount(Criteria $criteria, $distinct = false, $con = null)
{
// we're going to modify criteria, so copy it first
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsFieldI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsFieldI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$rs = ProductOptionsFieldI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Method to select one object from the DB.
*
* @param Criteria $criteria object used to create the SELECT statement.
* @param Connection $con
* @return ProductOptionsFieldI18n
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectOne(Criteria $criteria, $con = null)
{
$critcopy = clone $criteria;
$critcopy->setLimit(1);
$objects = ProductOptionsFieldI18nPeer::doSelect($critcopy, $con);
if ($objects) {
return $objects[0];
}
return null;
}
/**
* Method to do selects.
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con
* @return ProductOptionsFieldI18n[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelect(Criteria $criteria, $con = null)
{
return ProductOptionsFieldI18nPeer::populateObjects(ProductOptionsFieldI18nPeer::doSelectRS($criteria, $con));
}
/**
* Prepares the Criteria object and uses the parent doSelect()
* method to get a ResultSet.
*
* Use this method directly if you want to just get the resultset
* (instead of an array of objects).
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con the connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return ResultSet The resultset object with numerically-indexed fields.
* @see BasePeer::doSelect()
*/
public static function doSelectRS(Criteria $criteria, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if (!$criteria->getSelectColumns()) {
$criteria = clone $criteria;
ProductOptionsFieldI18nPeer::addSelectColumns($criteria);
}
if (stEventDispatcher::getInstance()->getListeners('BasePeer.preDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'BasePeer.preDoSelectRs'));
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
// BasePeer returns a Creole ResultSet, set to return
// rows indexed numerically.
$rs = BasePeer::doSelect($criteria, $con);
if (stEventDispatcher::getInstance()->getListeners('BasePeer.postDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($rs, 'BasePeer.postDoSelectRs'));
}
return $rs;
}
/**
* The returned array will contain objects of the default type or
* objects that inherit from the default.
*
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function populateObjects(ResultSet $rs)
{
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
// set the class once to avoid overhead in the loop
$cls = ProductOptionsFieldI18nPeer::getOMClass();
$cls = Propel::import($cls);
// populate the object(s)
while($rs->next()) {
$obj = new $cls();
$obj->hydrate($rs);
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj) : $obj;
}
return $results;
}
/**
* Returns the number of rows matching criteria, joining the related ProductOptionsField table
*
* @param Criteria $c
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCountJoinProductOptionsField(Criteria $criteria, $distinct = false, $con = null)
{
// we're going to modify criteria, so copy it first
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsFieldI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsFieldI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$criteria->addJoin(ProductOptionsFieldI18nPeer::ID, ProductOptionsFieldPeer::ID);
$rs = ProductOptionsFieldI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Selects a collection of ProductOptionsFieldI18n objects pre-filled with their ProductOptionsField objects.
*
* @return ProductOptionsFieldI18n[] Array of ProductOptionsFieldI18n objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinProductOptionsField(Criteria $c, $con = null)
{
$c = clone $c;
// Set the correct dbName if it has not been overridden
if ($c->getDbName() == Propel::getDefaultDB()) {
$c->setDbName(self::DATABASE_NAME);
}
ProductOptionsFieldI18nPeer::addSelectColumns($c);
ProductOptionsFieldPeer::addSelectColumns($c);
$c->addJoin(ProductOptionsFieldI18nPeer::ID, ProductOptionsFieldPeer::ID);
$rs = ProductOptionsFieldI18nPeer::doSelectRs($c, $con);
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
while($rs->next()) {
$obj1 = new ProductOptionsFieldI18n();
$startcol = $obj1->hydrate($rs);
if ($obj1->getId())
{
$obj2 = new ProductOptionsField();
$obj2->hydrate($rs, $startcol);
$obj2->addProductOptionsFieldI18n($obj1);
}
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj1) : $obj1;;
}
return $results;
}
/**
* Returns the number of rows matching criteria, joining all related tables
*
* @param Criteria $c
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCountJoinAll(Criteria $criteria, $distinct = false, $con = null)
{
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsFieldI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsFieldI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$criteria->addJoin(ProductOptionsFieldI18nPeer::ID, ProductOptionsFieldPeer::ID);
$rs = ProductOptionsFieldI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Selects a collection of ProductOptionsFieldI18n objects pre-filled with all related objects.
*
* @return ProductOptionsFieldI18n[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinAll(Criteria $c, $con = null)
{
$c = clone $c;
// Set the correct dbName if it has not been overridden
if ($c->getDbName() == Propel::getDefaultDB()) {
$c->setDbName(self::DATABASE_NAME);
}
ProductOptionsFieldI18nPeer::addSelectColumns($c);
$startcol2 = (ProductOptionsFieldI18nPeer::NUM_COLUMNS - ProductOptionsFieldI18nPeer::NUM_LAZY_LOAD_COLUMNS) + 1;
ProductOptionsFieldPeer::addSelectColumns($c);
$startcol3 = $startcol2 + ProductOptionsFieldPeer::NUM_COLUMNS;
$c->addJoin(ProductOptionsFieldI18nPeer::ID, ProductOptionsFieldPeer::ID);
$rs = BasePeer::doSelect($c, $con);
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
while($rs->next()) {
$omClass = ProductOptionsFieldI18nPeer::getOMClass();
$cls = Propel::import($omClass);
$obj1 = new $cls();
$obj1->hydrate($rs);
// Add objects for joined ProductOptionsField rows
$omClass = ProductOptionsFieldPeer::getOMClass();
$cls = Propel::import($omClass);
$obj2 = new $cls();
$obj2->hydrate($rs, $startcol2);
$newObject = true;
for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
$temp_obj1 = $results[$j];
$temp_obj2 = $temp_obj1->getProductOptionsField(); // CHECKME
if (null !== $temp_obj2 && $temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
$newObject = false;
$temp_obj2->addProductOptionsFieldI18n($obj1); // CHECKME
break;
}
}
if ($newObject) {
$obj2->initProductOptionsFieldI18ns();
$obj2->addProductOptionsFieldI18n($obj1);
}
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj1) : $obj1;
}
return $results;
}
/**
* Returns the TableMap related to this peer.
* This method is not needed for general use but a specific application could have a need.
* @return TableMap
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getTableMap()
{
return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
}
/**
* The class that the Peer will make instances of.
*
* This uses a dot-path notation which is tranalted into a path
* relative to a location on the PHP include_path.
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
*
* @return string path.to.ClassName
*/
public static function getOMClass()
{
return ProductOptionsFieldI18nPeer::CLASS_DEFAULT;
}
/**
* Method perform an INSERT on the database, given a ProductOptionsFieldI18n or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsFieldI18n object containing data that is used to create the INSERT statement.
* @param Connection $con the connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsFieldI18nPeer:doInsert:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsFieldI18nPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} else {
$criteria = $values->buildCriteria(); // build Criteria from ProductOptionsFieldI18n object
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->begin();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch(PropelException $e) {
$con->rollback();
throw $e;
}
foreach (sfMixer::getCallables('BaseProductOptionsFieldI18nPeer:doInsert:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsFieldI18nPeer', $values, $con, $pk);
}
return $pk;
}
/**
* Method perform an UPDATE on the database, given a ProductOptionsFieldI18n or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsFieldI18n object containing data that is used to create the UPDATE statement.
* @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
* @return int The number of affected rows (if supported by underlying database driver).
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doUpdate($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsFieldI18nPeer:doUpdate:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsFieldI18nPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$selectCriteria = new Criteria(self::DATABASE_NAME);
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
$comparison = $criteria->getComparison(ProductOptionsFieldI18nPeer::ID);
$selectCriteria->add(ProductOptionsFieldI18nPeer::ID, $criteria->remove(ProductOptionsFieldI18nPeer::ID), $comparison);
$comparison = $criteria->getComparison(ProductOptionsFieldI18nPeer::CULTURE);
$selectCriteria->add(ProductOptionsFieldI18nPeer::CULTURE, $criteria->remove(ProductOptionsFieldI18nPeer::CULTURE), $comparison);
} else { // $values is ProductOptionsFieldI18n object
$criteria = $values->buildCriteria(); // gets full criteria
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
}
// set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
foreach (sfMixer::getCallables('BaseProductOptionsFieldI18nPeer:doUpdate:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsFieldI18nPeer', $values, $con, $ret);
}
return $ret;
}
/**
* Method to DELETE all rows from the st_product_options_field_i18n table.
*
* @return int The number of affected rows (if supported by underlying database driver).
*/
public static function doDeleteAll($con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += BasePeer::doDeleteAll(ProductOptionsFieldI18nPeer::TABLE_NAME, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Method perform a DELETE on the database, given a ProductOptionsFieldI18n or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ProductOptionsFieldI18n object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param Connection $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doDelete($values, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(ProductOptionsFieldI18nPeer::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} elseif ($values instanceof ProductOptionsFieldI18n) {
$criteria = $values->buildPkeyCriteria();
} else {
// it must be the primary key
$criteria = new Criteria(self::DATABASE_NAME);
// primary key is composite; we therefore, expect
// the primary key passed to be an array of pkey
// values
if(count($values) == count($values, COUNT_RECURSIVE))
{
// array is not multi-dimensional
$values = array($values);
}
$vals = array();
foreach($values as $value)
{
$vals[0][] = $value[0];
$vals[1][] = $value[1];
}
$criteria->add(ProductOptionsFieldI18nPeer::ID, $vals[0], Criteria::IN);
$criteria->add(ProductOptionsFieldI18nPeer::CULTURE, $vals[1], Criteria::IN);
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += BasePeer::doDelete($criteria, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Validates all modified columns of given ProductOptionsFieldI18n object.
* If parameter $columns is either a single column name or an array of column names
* than only those columns are validated.
*
* NOTICE: This does not apply to primary or foreign keys for now.
*
* @param ProductOptionsFieldI18n $obj The object to validate.
* @param mixed $cols Column name or array of column names.
*
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
*/
public static function doValidate(ProductOptionsFieldI18n $obj, $cols = null)
{
$columns = array();
if ($cols) {
$dbMap = Propel::getDatabaseMap(ProductOptionsFieldI18nPeer::DATABASE_NAME);
$tableMap = $dbMap->getTable(ProductOptionsFieldI18nPeer::TABLE_NAME);
if (! is_array($cols)) {
$cols = array($cols);
}
foreach($cols as $colName) {
if ($tableMap->containsColumn($colName)) {
$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
$columns[$colName] = $obj->$get();
}
}
} else {
}
$res = BasePeer::doValidate(ProductOptionsFieldI18nPeer::DATABASE_NAME, ProductOptionsFieldI18nPeer::TABLE_NAME, $columns);
if ($res !== true) {
$request = sfContext::getInstance()->getRequest();
foreach ($res as $failed) {
$col = ProductOptionsFieldI18nPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
$request->setError($col, $failed->getMessage());
}
}
return $res;
}
/**
* Retrieve object using using composite pkey values.
* @param int $id
@param string $culture
* @param Connection $con
* @return ProductOptionsFieldI18n
*/
public static function retrieveByPK( $id, $culture, $con = null) {
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$criteria = new Criteria();
$criteria->add(ProductOptionsFieldI18nPeer::ID, $id);
$criteria->add(ProductOptionsFieldI18nPeer::CULTURE, $culture);
$v = ProductOptionsFieldI18nPeer::doSelect($criteria, $con);
return !empty($v) ? $v[0] : null;
}
} // BaseProductOptionsFieldI18nPeer
// static code to register the map builder for this Peer with the main Propel class
if (Propel::isInit()) {
// the MapBuilder classes register themselves with Propel during initialization
// so we need to load them here.
try {
BaseProductOptionsFieldI18nPeer::getMapBuilder();
} catch (Exception $e) {
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
}
} else {
// even if Propel is not yet initialized, the map builder class can be registered
// now and then it will be loaded when Propel initializes.
Propel::registerMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsFieldI18nMapBuilder');
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,776 @@
<?php
/**
* Base class that represents a row from the 'st_product_options_filter_i18n' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model.om
*/
abstract class BaseProductOptionsFilterI18n extends BaseObject implements Persistent {
protected static $dispatcher = null;
/**
* The value for the id field.
* @var int
*/
protected $id;
/**
* The value for the culture field.
* @var string
*/
protected $culture;
/**
* The value for the name field.
* @var string
*/
protected $name;
/**
* @var ProductOptionsFilter
*/
protected $aProductOptionsFilter;
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
* @var boolean
*/
protected $alreadyInSave = false;
/**
* Flag to prevent endless validation loop, if this object is referenced
* by another object which falls in this transaction.
* @var boolean
*/
protected $alreadyInValidation = false;
/**
* Get the [id] column value.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Get the [culture] column value.
*
* @return string
*/
public function getCulture()
{
return $this->culture;
}
/**
* Get the [name] column value.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set the value of [id] column.
*
* @param int $v new value
* @return void
*/
public function setId($v)
{
if ($v !== null && !is_int($v) && is_numeric($v)) {
$v = (int) $v;
}
if ($this->id !== $v) {
$this->id = $v;
$this->modifiedColumns[] = ProductOptionsFilterI18nPeer::ID;
}
if ($this->aProductOptionsFilter !== null && $this->aProductOptionsFilter->getId() !== $v) {
$this->aProductOptionsFilter = null;
}
} // setId()
/**
* Set the value of [culture] column.
*
* @param string $v new value
* @return void
*/
public function setCulture($v)
{
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->culture !== $v) {
$this->culture = $v;
$this->modifiedColumns[] = ProductOptionsFilterI18nPeer::CULTURE;
}
} // setCulture()
/**
* Set the value of [name] column.
*
* @param string $v new value
* @return void
*/
public function setName($v)
{
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->name !== $v) {
$this->name = $v;
$this->modifiedColumns[] = ProductOptionsFilterI18nPeer::NAME;
}
} // setName()
/**
* Hydrates (populates) the object variables with values from the database resultset.
*
* An offset (1-based "start column") is specified so that objects can be hydrated
* with a subset of the columns in the resultset rows. This is needed, for example,
* for results of JOIN queries where the resultset row includes columns from two or
* more tables.
*
* @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos.
* @param int $startcol 1-based offset column which indicates which restultset column to start with.
* @return int next starting column
* @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
*/
public function hydrate(ResultSet $rs, $startcol = 1)
{
try {
if ($this->getDispatcher()->getListeners('ProductOptionsFilterI18n.preHydrate')) {
$event = $this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFilterI18n.preHydrate', array('resultset' => $rs, 'startcol' => $startcol)));
$startcol = $event['startcol'];
}
$this->id = $rs->getInt($startcol + 0);
$this->culture = $rs->getString($startcol + 1);
$this->name = $rs->getString($startcol + 2);
$this->resetModified();
$this->setNew(false);
if ($this->getDispatcher()->getListeners('ProductOptionsFilterI18n.postHydrate')) {
$event = $this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFilterI18n.postHydrate', array('resultset' => $rs, 'startcol' => $startcol + 3)));
return $event['startcol'];
}
// FIXME - using NUM_COLUMNS may be clearer.
return $startcol + 3; // 3 = ProductOptionsFilterI18nPeer::NUM_COLUMNS - ProductOptionsFilterI18nPeer::NUM_LAZY_LOAD_COLUMNS).
} catch (Exception $e) {
throw new PropelException("Error populating ProductOptionsFilterI18n object", $e);
}
}
/**
* Removes this object from datastore and sets delete attribute.
*
* @param Connection $con
* @return void
* @throws PropelException
* @see BaseObject::setDeleted()
* @see BaseObject::isDeleted()
*/
public function delete($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("This object has already been deleted.");
}
if ($this->getDispatcher()->getListeners('ProductOptionsFilterI18n.preDelete')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFilterI18n.preDelete', array('con' => $con)));
}
if (sfMixer::hasCallables('BaseProductOptionsFilterI18n:delete:pre'))
{
foreach (sfMixer::getCallables('BaseProductOptionsFilterI18n:delete:pre') as $callable)
{
$ret = call_user_func($callable, $this, $con);
if ($ret)
{
return;
}
}
}
if ($con === null) {
$con = Propel::getConnection(ProductOptionsFilterI18nPeer::DATABASE_NAME);
}
try {
$con->begin();
ProductOptionsFilterI18nPeer::doDelete($this, $con);
$this->setDeleted(true);
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
if ($this->getDispatcher()->getListeners('ProductOptionsFilterI18n.postDelete')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFilterI18n.postDelete', array('con' => $con)));
}
if (sfMixer::hasCallables('BaseProductOptionsFilterI18n:delete:post'))
{
foreach (sfMixer::getCallables('BaseProductOptionsFilterI18n:delete:post') as $callable)
{
call_user_func($callable, $this, $con);
}
}
}
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed. This method
* wraps the doSave() worker method in a transaction.
*
* @param Connection $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see doSave()
*/
public function save($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("You cannot save an object that has been deleted.");
}
if (!$this->alreadyInSave) {
if ($this->getDispatcher()->getListeners('ProductOptionsFilterI18n.preSave')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFilterI18n.preSave', array('con' => $con)));
}
foreach (sfMixer::getCallables('BaseProductOptionsFilterI18n:save:pre') as $callable)
{
$affectedRows = call_user_func($callable, $this, $con);
if (is_int($affectedRows))
{
return $affectedRows;
}
}
}
if ($con === null) {
$con = Propel::getConnection(ProductOptionsFilterI18nPeer::DATABASE_NAME);
}
try {
$con->begin();
$affectedRows = $this->doSave($con);
$con->commit();
if (!$this->alreadyInSave) {
if ($this->getDispatcher()->getListeners('ProductOptionsFilterI18n.postSave')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsFilterI18n.postSave', array('con' => $con)));
}
foreach (sfMixer::getCallables('BaseProductOptionsFilterI18n:save:post') as $callable)
{
call_user_func($callable, $this, $con, $affectedRows);
}
}
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Stores the object in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param Connection $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave($con)
{
$affectedRows = 0; // initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aProductOptionsFilter !== null) {
if ($this->aProductOptionsFilter->isModified() || $this->aProductOptionsFilter->getCurrentProductOptionsFilterI18n()->isModified()) {
$affectedRows += $this->aProductOptionsFilter->save($con);
}
$this->setProductOptionsFilter($this->aProductOptionsFilter);
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = ProductOptionsFilterI18nPeer::doInsert($this, $con);
$affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setNew(false);
} else {
$affectedRows += ProductOptionsFilterI18nPeer::doUpdate($this, $con);
}
$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
} // doSave()
/**
* Array of ValidationFailed objects.
* @var array ValidationFailed[]
*/
protected $validationFailures = array();
/**
* Gets any ValidationFailed objects that resulted from last call to validate().
*
*
* @return array ValidationFailed[]
* @see validate()
*/
public function getValidationFailures()
{
return $this->validationFailures;
}
/**
* Validates the objects modified field values and all objects related to this table.
*
* If $columns is either a column name or an array of column names
* only those columns are validated.
*
* @param mixed $columns Column name or an array of column names.
* @return boolean Whether all columns pass validation.
* @see doValidate()
* @see getValidationFailures()
*/
public function validate($columns = null)
{
$res = $this->doValidate($columns);
if ($res === true) {
$this->validationFailures = array();
return true;
} else {
$this->validationFailures = $res;
return false;
}
}
/**
* This function performs the validation work for complex object models.
*
* In addition to checking the current object, all related objects will
* also be validated. If all pass then <code>true</code> is returned; otherwise
* an aggreagated array of ValidationFailed objects will be returned.
*
* @param array $columns Array of column names to validate.
* @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
*/
protected function doValidate($columns = null)
{
if (!$this->alreadyInValidation) {
$this->alreadyInValidation = true;
$retval = null;
$failureMap = array();
// We call the validate method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aProductOptionsFilter !== null) {
if (!$this->aProductOptionsFilter->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aProductOptionsFilter->getValidationFailures());
}
}
if (($retval = ProductOptionsFilterI18nPeer::doValidate($this, $columns)) !== true) {
$failureMap = array_merge($failureMap, $retval);
}
$this->alreadyInValidation = false;
}
return (!empty($failureMap) ? $failureMap : true);
}
/**
* Retrieves a field from the object by name passed in as a string.
*
* @param string $name name
* @param string $type The type of fieldname the $name is of:
* one of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return mixed Value of field.
*/
public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
{
$pos = ProductOptionsFilterI18nPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
return $this->getByPosition($pos);
}
/**
* Retrieves a field from the object by Position as specified in the xml schema.
* Zero-based.
*
* @param int $pos position in xml schema
* @return mixed Value of field at $pos
*/
public function getByPosition($pos)
{
switch($pos) {
case 0:
return $this->getId();
break;
case 1:
return $this->getCulture();
break;
case 2:
return $this->getName();
break;
default:
return null;
break;
} // switch()
}
/**
* Exports the object as an array.
*
* You can specify the key type of the array by passing one of the class
* type constants.
*
* @param string $keyType One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return an associative array containing the field names (as keys) and field values
*/
public function toArray($keyType = BasePeer::TYPE_PHPNAME)
{
$keys = ProductOptionsFilterI18nPeer::getFieldNames($keyType);
$result = array(
$keys[0] => $this->getId(),
$keys[1] => $this->getCulture(),
$keys[2] => $this->getName(),
);
return $result;
}
/**
* Sets a field from the object by name passed in as a string.
*
* @param string $name peer name
* @param mixed $value field value
* @param string $type The type of fieldname the $name is of:
* one of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return void
*/
public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
{
$pos = ProductOptionsFilterI18nPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
return $this->setByPosition($pos, $value);
}
/**
* Sets a field from the object by Position as specified in the xml schema.
* Zero-based.
*
* @param int $pos position in xml schema
* @param mixed $value field value
* @return void
*/
public function setByPosition($pos, $value)
{
switch($pos) {
case 0:
$this->setId($value);
break;
case 1:
$this->setCulture($value);
break;
case 2:
$this->setName($value);
break;
} // switch()
}
/**
* Populates the object using an array.
*
* This is particularly useful when populating an object from one of the
* request arrays (e.g. $_POST). This method goes through the column
* names, checking to see whether a matching key exists in populated
* array. If so the setByName() method is called for that column.
*
* You can specify the key type of the array by additionally passing one
* of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
* TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
*
* @param array $arr An array to populate the object from.
* @param string $keyType The type of keys the array uses.
* @return void
*/
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
{
$keys = ProductOptionsFilterI18nPeer::getFieldNames($keyType);
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
if (array_key_exists($keys[1], $arr)) $this->setCulture($arr[$keys[1]]);
if (array_key_exists($keys[2], $arr)) $this->setName($arr[$keys[2]]);
}
/**
* Build a Criteria object containing the values of all modified columns in this object.
*
* @return Criteria The Criteria object containing all modified values.
*/
public function buildCriteria()
{
$criteria = new Criteria(ProductOptionsFilterI18nPeer::DATABASE_NAME);
if ($this->isColumnModified(ProductOptionsFilterI18nPeer::ID)) $criteria->add(ProductOptionsFilterI18nPeer::ID, $this->id);
if ($this->isColumnModified(ProductOptionsFilterI18nPeer::CULTURE)) $criteria->add(ProductOptionsFilterI18nPeer::CULTURE, $this->culture);
if ($this->isColumnModified(ProductOptionsFilterI18nPeer::NAME)) $criteria->add(ProductOptionsFilterI18nPeer::NAME, $this->name);
return $criteria;
}
/**
* Builds a Criteria object containing the primary key for this object.
*
* Unlike buildCriteria() this method includes the primary key values regardless
* of whether or not they have been modified.
*
* @return Criteria The Criteria object containing value(s) for primary key(s).
*/
public function buildPkeyCriteria()
{
$criteria = new Criteria(ProductOptionsFilterI18nPeer::DATABASE_NAME);
$criteria->add(ProductOptionsFilterI18nPeer::ID, $this->id);
$criteria->add(ProductOptionsFilterI18nPeer::CULTURE, $this->culture);
return $criteria;
}
/**
* Returns the composite primary key for this object.
* The array elements will be in same order as specified in XML.
* @return array
*/
public function getPrimaryKey()
{
return array($this->getId(), $this->getCulture());
}
/**
* Returns [composite] primary key fields
*
* @param string $keyType
* @return array
*/
public function getPrimaryKeyFields($keyType = BasePeer::TYPE_FIELDNAME)
{
return array(ProductOptionsFilterI18nPeer::translateFieldName('id', BasePeer::TYPE_FIELDNAME, $keyType), ProductOptionsFilterI18nPeer::translateFieldName('culture', BasePeer::TYPE_FIELDNAME, $keyType));
}
/**
* Set the [composite] primary key.
*
* @param array $keys The elements of the composite key (order must match the order in XML file).
* @return void
*/
public function setPrimaryKey($keys)
{
$this->setId($keys[0]);
$this->setCulture($keys[1]);
}
/**
* Sets contents of passed object to values from current object.
*
* If desired, this method can also make copies of all associated (fkey referrers)
* objects.
*
* @param object $copyObj An object of ProductOptionsFilterI18n (or compatible) type.
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
* @throws PropelException
*/
public function copyInto($copyObj, $deepCopy = false)
{
$copyObj->setName($this->name);
$copyObj->setNew(true);
$copyObj->setId(NULL); // this is a pkey column, so set to default value
$copyObj->setCulture(NULL); // this is a pkey column, so set to default value
}
/**
* Makes a copy of this object that will be inserted as a new row in table when saved.
* It creates a new object filling in the simple attributes, but skipping any primary
* keys that are defined for the table.
*
* If desired, this method can also make copies of all associated (fkey referrers)
* objects.
*
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
* @return ProductOptionsFilterI18n Clone of current object.
* @throws PropelException
*/
public function copy($deepCopy = false)
{
// we use get_class(), because this might be a subclass
$clazz = get_class($this);
$copyObj = new $clazz();
$this->copyInto($copyObj, $deepCopy);
return $copyObj;
}
/**
* Returns a peer instance associated with this om.
*
* @return string Peer class name
*/
public function getPeer()
{
return 'ProductOptionsFilterI18nPeer';
}
/**
* Declares an association between this object and a ProductOptionsFilter object.
*
* @param ProductOptionsFilter $v
* @return void
* @throws PropelException
*/
public function setProductOptionsFilter($v)
{
if ($v === null) {
$this->setId(NULL);
} else {
$this->setId($v->getId());
}
$this->aProductOptionsFilter = $v;
}
/**
* Get the associated ProductOptionsFilter object
*
* @param Connection Optional Connection object.
* @return ProductOptionsFilter The associated ProductOptionsFilter object.
* @throws PropelException
*/
public function getProductOptionsFilter($con = null)
{
if ($this->aProductOptionsFilter === null && ($this->id !== null)) {
// include the related Peer class
$this->aProductOptionsFilter = ProductOptionsFilterPeer::retrieveByPK($this->id, $con);
/* The following can be used instead of the line above to
guarantee the related object contains a reference
to this object, but this level of coupling
may be undesirable in many circumstances.
As it can lead to a db query with many results that may
never be used.
$obj = ProductOptionsFilterPeer::retrieveByPK($this->id, $con);
$obj->addProductOptionsFilters($this);
*/
}
return $this->aProductOptionsFilter;
}
public function getDispatcher()
{
if (null === self::$dispatcher)
{
self::$dispatcher = stEventDispatcher::getInstance();
}
return self::$dispatcher;
}
public function __call($method, $arguments)
{
$event = $this->getDispatcher()->notifyUntil(new sfEvent($this, 'ProductOptionsFilterI18n.' . $method, array('arguments' => $arguments, 'method' => $method)));
if ($event->isProcessed())
{
return $event->getReturnValue();
}
if (!$callable = sfMixer::getCallable('BaseProductOptionsFilterI18n:'.$method))
{
throw new sfException(sprintf('Call to undefined method BaseProductOptionsFilterI18n::%s', $method));
}
array_unshift($arguments, $this);
return call_user_func_array($callable, $arguments);
}
} // BaseProductOptionsFilterI18n

View File

@@ -0,0 +1,834 @@
<?php
/**
* Base static class for performing query and update operations on the 'st_product_options_filter_i18n' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model.om
*/
abstract class BaseProductOptionsFilterI18nPeer {
/** the default database name for this class */
const DATABASE_NAME = 'propel';
/** the table name for this class */
const TABLE_NAME = 'st_product_options_filter_i18n';
/** A class that can be returned by this peer. */
const CLASS_DEFAULT = 'plugins.stProductOptionsPlugin.lib.model.ProductOptionsFilterI18n';
/** The total number of columns. */
const NUM_COLUMNS = 3;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
/** the column name for the ID field */
const ID = 'st_product_options_filter_i18n.ID';
/** the column name for the CULTURE field */
const CULTURE = 'st_product_options_filter_i18n.CULTURE';
/** the column name for the NAME field */
const NAME = 'st_product_options_filter_i18n.NAME';
/** The PHP to DB Name Mapping */
private static $phpNameMap = null;
/**
* holds an array of fieldnames
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('Id', 'Culture', 'Name', ),
BasePeer::TYPE_COLNAME => array (ProductOptionsFilterI18nPeer::ID, ProductOptionsFilterI18nPeer::CULTURE, ProductOptionsFilterI18nPeer::NAME, ),
BasePeer::TYPE_FIELDNAME => array ('id', 'culture', 'name', ),
BasePeer::TYPE_NUM => array (0, 1, 2, )
);
/**
* holds an array of keys for quick access to the fieldnames array
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Culture' => 1, 'Name' => 2, ),
BasePeer::TYPE_COLNAME => array (ProductOptionsFilterI18nPeer::ID => 0, ProductOptionsFilterI18nPeer::CULTURE => 1, ProductOptionsFilterI18nPeer::NAME => 2, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'culture' => 1, 'name' => 2, ),
BasePeer::TYPE_NUM => array (0, 1, 2, )
);
protected static $hydrateMethod = null;
protected static $postHydrateMethod = null;
public static function setHydrateMethod($callback)
{
self::$hydrateMethod = $callback;
}
public static function setPostHydrateMethod($callback)
{
self::$postHydrateMethod = $callback;
}
/**
* @return MapBuilder the map builder for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getMapBuilder()
{
return BasePeer::getMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsFilterI18nMapBuilder');
}
/**
* Gets a map (hash) of PHP names to DB column names.
*
* @return array The PHP to DB name map for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
*/
public static function getPhpNameMap()
{
if (self::$phpNameMap === null) {
$map = ProductOptionsFilterI18nPeer::getTableMap();
$columns = $map->getColumns();
$nameMap = array();
foreach ($columns as $column) {
$nameMap[$column->getPhpName()] = $column->getColumnName();
}
self::$phpNameMap = $nameMap;
}
return self::$phpNameMap;
}
/**
* Translates a fieldname to another type
*
* @param string $name field name
* @param string $fromType One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @param string $toType One of the class type constants
* @return string translated name of the field.
*/
static public function translateFieldName($name, $fromType, $toType)
{
$toNames = self::getFieldNames($toType);
$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
if ($key === null) {
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
}
return $toNames[$key];
}
/**
* Returns an array of of field names.
*
* @param string $type The type of fieldnames to return:
* One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return array A list of field names
*/
static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
{
if (!array_key_exists($type, self::$fieldNames)) {
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
}
return self::$fieldNames[$type];
}
/**
* Convenience method which changes table.column to alias.column.
*
* Using this method you can maintain SQL abstraction while using column aliases.
* <code>
* $c->addAlias("alias1", TablePeer::TABLE_NAME);
* $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
* </code>
* @param string $alias The alias for the current table.
* @param string $column The column name for current table. (i.e. ProductOptionsFilterI18nPeer::COLUMN_NAME).
* @return string
*/
public static function alias($alias, $column)
{
return str_replace(ProductOptionsFilterI18nPeer::TABLE_NAME.'.', $alias.'.', $column);
}
/**
* Add all the columns needed to create a new object.
*
* Note: any columns that were marked with lazyLoad="true" in the
* XML schema will not be added to the select list and only loaded
* on demand.
*
* @param criteria object containing the columns to add.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function addSelectColumns(Criteria $criteria)
{
$criteria->addSelectColumn(ProductOptionsFilterI18nPeer::ID);
$criteria->addSelectColumn(ProductOptionsFilterI18nPeer::CULTURE);
$criteria->addSelectColumn(ProductOptionsFilterI18nPeer::NAME);
if (stEventDispatcher::getInstance()->getListeners('ProductOptionsFilterI18nPeer.postAddSelectColumns')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'ProductOptionsFilterI18nPeer.postAddSelectColumns'));
}
}
const COUNT = 'COUNT(st_product_options_filter_i18n.ID)';
const COUNT_DISTINCT = 'COUNT(DISTINCT st_product_options_filter_i18n.ID)';
/**
* Returns the number of rows matching criteria.
*
* @param Criteria $criteria
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCount(Criteria $criteria, $distinct = false, $con = null)
{
// we're going to modify criteria, so copy it first
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsFilterI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsFilterI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$rs = ProductOptionsFilterI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Method to select one object from the DB.
*
* @param Criteria $criteria object used to create the SELECT statement.
* @param Connection $con
* @return ProductOptionsFilterI18n
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectOne(Criteria $criteria, $con = null)
{
$critcopy = clone $criteria;
$critcopy->setLimit(1);
$objects = ProductOptionsFilterI18nPeer::doSelect($critcopy, $con);
if ($objects) {
return $objects[0];
}
return null;
}
/**
* Method to do selects.
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con
* @return ProductOptionsFilterI18n[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelect(Criteria $criteria, $con = null)
{
return ProductOptionsFilterI18nPeer::populateObjects(ProductOptionsFilterI18nPeer::doSelectRS($criteria, $con));
}
/**
* Prepares the Criteria object and uses the parent doSelect()
* method to get a ResultSet.
*
* Use this method directly if you want to just get the resultset
* (instead of an array of objects).
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con the connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return ResultSet The resultset object with numerically-indexed fields.
* @see BasePeer::doSelect()
*/
public static function doSelectRS(Criteria $criteria, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if (!$criteria->getSelectColumns()) {
$criteria = clone $criteria;
ProductOptionsFilterI18nPeer::addSelectColumns($criteria);
}
if (stEventDispatcher::getInstance()->getListeners('BasePeer.preDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'BasePeer.preDoSelectRs'));
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
// BasePeer returns a Creole ResultSet, set to return
// rows indexed numerically.
$rs = BasePeer::doSelect($criteria, $con);
if (stEventDispatcher::getInstance()->getListeners('BasePeer.postDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($rs, 'BasePeer.postDoSelectRs'));
}
return $rs;
}
/**
* The returned array will contain objects of the default type or
* objects that inherit from the default.
*
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function populateObjects(ResultSet $rs)
{
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
// set the class once to avoid overhead in the loop
$cls = ProductOptionsFilterI18nPeer::getOMClass();
$cls = Propel::import($cls);
// populate the object(s)
while($rs->next()) {
$obj = new $cls();
$obj->hydrate($rs);
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj) : $obj;
}
return $results;
}
/**
* Returns the number of rows matching criteria, joining the related ProductOptionsFilter table
*
* @param Criteria $c
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCountJoinProductOptionsFilter(Criteria $criteria, $distinct = false, $con = null)
{
// we're going to modify criteria, so copy it first
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsFilterI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsFilterI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$criteria->addJoin(ProductOptionsFilterI18nPeer::ID, ProductOptionsFilterPeer::ID);
$rs = ProductOptionsFilterI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Selects a collection of ProductOptionsFilterI18n objects pre-filled with their ProductOptionsFilter objects.
*
* @return ProductOptionsFilterI18n[] Array of ProductOptionsFilterI18n objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinProductOptionsFilter(Criteria $c, $con = null)
{
$c = clone $c;
// Set the correct dbName if it has not been overridden
if ($c->getDbName() == Propel::getDefaultDB()) {
$c->setDbName(self::DATABASE_NAME);
}
ProductOptionsFilterI18nPeer::addSelectColumns($c);
ProductOptionsFilterPeer::addSelectColumns($c);
$c->addJoin(ProductOptionsFilterI18nPeer::ID, ProductOptionsFilterPeer::ID);
$rs = ProductOptionsFilterI18nPeer::doSelectRs($c, $con);
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
while($rs->next()) {
$obj1 = new ProductOptionsFilterI18n();
$startcol = $obj1->hydrate($rs);
if ($obj1->getId())
{
$obj2 = new ProductOptionsFilter();
$obj2->hydrate($rs, $startcol);
$obj2->addProductOptionsFilterI18n($obj1);
}
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj1) : $obj1;;
}
return $results;
}
/**
* Returns the number of rows matching criteria, joining all related tables
*
* @param Criteria $c
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCountJoinAll(Criteria $criteria, $distinct = false, $con = null)
{
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsFilterI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsFilterI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$criteria->addJoin(ProductOptionsFilterI18nPeer::ID, ProductOptionsFilterPeer::ID);
$rs = ProductOptionsFilterI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Selects a collection of ProductOptionsFilterI18n objects pre-filled with all related objects.
*
* @return ProductOptionsFilterI18n[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinAll(Criteria $c, $con = null)
{
$c = clone $c;
// Set the correct dbName if it has not been overridden
if ($c->getDbName() == Propel::getDefaultDB()) {
$c->setDbName(self::DATABASE_NAME);
}
ProductOptionsFilterI18nPeer::addSelectColumns($c);
$startcol2 = (ProductOptionsFilterI18nPeer::NUM_COLUMNS - ProductOptionsFilterI18nPeer::NUM_LAZY_LOAD_COLUMNS) + 1;
ProductOptionsFilterPeer::addSelectColumns($c);
$startcol3 = $startcol2 + ProductOptionsFilterPeer::NUM_COLUMNS;
$c->addJoin(ProductOptionsFilterI18nPeer::ID, ProductOptionsFilterPeer::ID);
$rs = BasePeer::doSelect($c, $con);
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
while($rs->next()) {
$omClass = ProductOptionsFilterI18nPeer::getOMClass();
$cls = Propel::import($omClass);
$obj1 = new $cls();
$obj1->hydrate($rs);
// Add objects for joined ProductOptionsFilter rows
$omClass = ProductOptionsFilterPeer::getOMClass();
$cls = Propel::import($omClass);
$obj2 = new $cls();
$obj2->hydrate($rs, $startcol2);
$newObject = true;
for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
$temp_obj1 = $results[$j];
$temp_obj2 = $temp_obj1->getProductOptionsFilter(); // CHECKME
if (null !== $temp_obj2 && $temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
$newObject = false;
$temp_obj2->addProductOptionsFilterI18n($obj1); // CHECKME
break;
}
}
if ($newObject) {
$obj2->initProductOptionsFilterI18ns();
$obj2->addProductOptionsFilterI18n($obj1);
}
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj1) : $obj1;
}
return $results;
}
/**
* Returns the TableMap related to this peer.
* This method is not needed for general use but a specific application could have a need.
* @return TableMap
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getTableMap()
{
return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
}
/**
* The class that the Peer will make instances of.
*
* This uses a dot-path notation which is tranalted into a path
* relative to a location on the PHP include_path.
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
*
* @return string path.to.ClassName
*/
public static function getOMClass()
{
return ProductOptionsFilterI18nPeer::CLASS_DEFAULT;
}
/**
* Method perform an INSERT on the database, given a ProductOptionsFilterI18n or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsFilterI18n object containing data that is used to create the INSERT statement.
* @param Connection $con the connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsFilterI18nPeer:doInsert:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsFilterI18nPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} else {
$criteria = $values->buildCriteria(); // build Criteria from ProductOptionsFilterI18n object
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->begin();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch(PropelException $e) {
$con->rollback();
throw $e;
}
foreach (sfMixer::getCallables('BaseProductOptionsFilterI18nPeer:doInsert:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsFilterI18nPeer', $values, $con, $pk);
}
return $pk;
}
/**
* Method perform an UPDATE on the database, given a ProductOptionsFilterI18n or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsFilterI18n object containing data that is used to create the UPDATE statement.
* @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
* @return int The number of affected rows (if supported by underlying database driver).
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doUpdate($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsFilterI18nPeer:doUpdate:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsFilterI18nPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$selectCriteria = new Criteria(self::DATABASE_NAME);
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
$comparison = $criteria->getComparison(ProductOptionsFilterI18nPeer::ID);
$selectCriteria->add(ProductOptionsFilterI18nPeer::ID, $criteria->remove(ProductOptionsFilterI18nPeer::ID), $comparison);
$comparison = $criteria->getComparison(ProductOptionsFilterI18nPeer::CULTURE);
$selectCriteria->add(ProductOptionsFilterI18nPeer::CULTURE, $criteria->remove(ProductOptionsFilterI18nPeer::CULTURE), $comparison);
} else { // $values is ProductOptionsFilterI18n object
$criteria = $values->buildCriteria(); // gets full criteria
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
}
// set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
foreach (sfMixer::getCallables('BaseProductOptionsFilterI18nPeer:doUpdate:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsFilterI18nPeer', $values, $con, $ret);
}
return $ret;
}
/**
* Method to DELETE all rows from the st_product_options_filter_i18n table.
*
* @return int The number of affected rows (if supported by underlying database driver).
*/
public static function doDeleteAll($con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += BasePeer::doDeleteAll(ProductOptionsFilterI18nPeer::TABLE_NAME, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Method perform a DELETE on the database, given a ProductOptionsFilterI18n or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ProductOptionsFilterI18n object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param Connection $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doDelete($values, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(ProductOptionsFilterI18nPeer::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} elseif ($values instanceof ProductOptionsFilterI18n) {
$criteria = $values->buildPkeyCriteria();
} else {
// it must be the primary key
$criteria = new Criteria(self::DATABASE_NAME);
// primary key is composite; we therefore, expect
// the primary key passed to be an array of pkey
// values
if(count($values) == count($values, COUNT_RECURSIVE))
{
// array is not multi-dimensional
$values = array($values);
}
$vals = array();
foreach($values as $value)
{
$vals[0][] = $value[0];
$vals[1][] = $value[1];
}
$criteria->add(ProductOptionsFilterI18nPeer::ID, $vals[0], Criteria::IN);
$criteria->add(ProductOptionsFilterI18nPeer::CULTURE, $vals[1], Criteria::IN);
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += BasePeer::doDelete($criteria, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Validates all modified columns of given ProductOptionsFilterI18n object.
* If parameter $columns is either a single column name or an array of column names
* than only those columns are validated.
*
* NOTICE: This does not apply to primary or foreign keys for now.
*
* @param ProductOptionsFilterI18n $obj The object to validate.
* @param mixed $cols Column name or array of column names.
*
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
*/
public static function doValidate(ProductOptionsFilterI18n $obj, $cols = null)
{
$columns = array();
if ($cols) {
$dbMap = Propel::getDatabaseMap(ProductOptionsFilterI18nPeer::DATABASE_NAME);
$tableMap = $dbMap->getTable(ProductOptionsFilterI18nPeer::TABLE_NAME);
if (! is_array($cols)) {
$cols = array($cols);
}
foreach($cols as $colName) {
if ($tableMap->containsColumn($colName)) {
$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
$columns[$colName] = $obj->$get();
}
}
} else {
}
$res = BasePeer::doValidate(ProductOptionsFilterI18nPeer::DATABASE_NAME, ProductOptionsFilterI18nPeer::TABLE_NAME, $columns);
if ($res !== true) {
$request = sfContext::getInstance()->getRequest();
foreach ($res as $failed) {
$col = ProductOptionsFilterI18nPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
$request->setError($col, $failed->getMessage());
}
}
return $res;
}
/**
* Retrieve object using using composite pkey values.
* @param int $id
@param string $culture
* @param Connection $con
* @return ProductOptionsFilterI18n
*/
public static function retrieveByPK( $id, $culture, $con = null) {
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$criteria = new Criteria();
$criteria->add(ProductOptionsFilterI18nPeer::ID, $id);
$criteria->add(ProductOptionsFilterI18nPeer::CULTURE, $culture);
$v = ProductOptionsFilterI18nPeer::doSelect($criteria, $con);
return !empty($v) ? $v[0] : null;
}
} // BaseProductOptionsFilterI18nPeer
// static code to register the map builder for this Peer with the main Propel class
if (Propel::isInit()) {
// the MapBuilder classes register themselves with Propel during initialization
// so we need to load them here.
try {
BaseProductOptionsFilterI18nPeer::getMapBuilder();
} catch (Exception $e) {
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
}
} else {
// even if Propel is not yet initialized, the map builder class can be registered
// now and then it will be loaded when Propel initializes.
Propel::registerMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsFilterI18nMapBuilder');
}

View File

@@ -0,0 +1,769 @@
<?php
/**
* Base static class for performing query and update operations on the 'st_product_options_filter' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model.om
*/
abstract class BaseProductOptionsFilterPeer {
/** the default database name for this class */
const DATABASE_NAME = 'propel';
/** the table name for this class */
const TABLE_NAME = 'st_product_options_filter';
/** A class that can be returned by this peer. */
const CLASS_DEFAULT = 'plugins.stProductOptionsPlugin.lib.model.ProductOptionsFilter';
/** The total number of columns. */
const NUM_COLUMNS = 9;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
/** the column name for the CREATED_AT field */
const CREATED_AT = 'st_product_options_filter.CREATED_AT';
/** the column name for the UPDATED_AT field */
const UPDATED_AT = 'st_product_options_filter.UPDATED_AT';
/** the column name for the ID field */
const ID = 'st_product_options_filter.ID';
/** the column name for the OPT_NAME field */
const OPT_NAME = 'st_product_options_filter.OPT_NAME';
/** the column name for the FILTER_TYPE field */
const FILTER_TYPE = 'st_product_options_filter.FILTER_TYPE';
/** the column name for the RANK field */
const RANK = 'st_product_options_filter.RANK';
/** the column name for the PRICE_FROM field */
const PRICE_FROM = 'st_product_options_filter.PRICE_FROM';
/** the column name for the PRICE_TO field */
const PRICE_TO = 'st_product_options_filter.PRICE_TO';
/** the column name for the IS_VISIBLE field */
const IS_VISIBLE = 'st_product_options_filter.IS_VISIBLE';
/** The PHP to DB Name Mapping */
private static $phpNameMap = null;
/**
* holds an array of fieldnames
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('CreatedAt', 'UpdatedAt', 'Id', 'OptName', 'FilterType', 'Rank', 'PriceFrom', 'PriceTo', 'IsVisible', ),
BasePeer::TYPE_COLNAME => array (ProductOptionsFilterPeer::CREATED_AT, ProductOptionsFilterPeer::UPDATED_AT, ProductOptionsFilterPeer::ID, ProductOptionsFilterPeer::OPT_NAME, ProductOptionsFilterPeer::FILTER_TYPE, ProductOptionsFilterPeer::RANK, ProductOptionsFilterPeer::PRICE_FROM, ProductOptionsFilterPeer::PRICE_TO, ProductOptionsFilterPeer::IS_VISIBLE, ),
BasePeer::TYPE_FIELDNAME => array ('created_at', 'updated_at', 'id', 'opt_name', 'filter_type', 'rank', 'price_from', 'price_to', 'is_visible', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, )
);
/**
* holds an array of keys for quick access to the fieldnames array
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('CreatedAt' => 0, 'UpdatedAt' => 1, 'Id' => 2, 'OptName' => 3, 'FilterType' => 4, 'Rank' => 5, 'PriceFrom' => 6, 'PriceTo' => 7, 'IsVisible' => 8, ),
BasePeer::TYPE_COLNAME => array (ProductOptionsFilterPeer::CREATED_AT => 0, ProductOptionsFilterPeer::UPDATED_AT => 1, ProductOptionsFilterPeer::ID => 2, ProductOptionsFilterPeer::OPT_NAME => 3, ProductOptionsFilterPeer::FILTER_TYPE => 4, ProductOptionsFilterPeer::RANK => 5, ProductOptionsFilterPeer::PRICE_FROM => 6, ProductOptionsFilterPeer::PRICE_TO => 7, ProductOptionsFilterPeer::IS_VISIBLE => 8, ),
BasePeer::TYPE_FIELDNAME => array ('created_at' => 0, 'updated_at' => 1, 'id' => 2, 'opt_name' => 3, 'filter_type' => 4, 'rank' => 5, 'price_from' => 6, 'price_to' => 7, 'is_visible' => 8, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, )
);
protected static $hydrateMethod = null;
protected static $postHydrateMethod = null;
public static function setHydrateMethod($callback)
{
self::$hydrateMethod = $callback;
}
public static function setPostHydrateMethod($callback)
{
self::$postHydrateMethod = $callback;
}
/**
* @return MapBuilder the map builder for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getMapBuilder()
{
return BasePeer::getMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsFilterMapBuilder');
}
/**
* Gets a map (hash) of PHP names to DB column names.
*
* @return array The PHP to DB name map for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
*/
public static function getPhpNameMap()
{
if (self::$phpNameMap === null) {
$map = ProductOptionsFilterPeer::getTableMap();
$columns = $map->getColumns();
$nameMap = array();
foreach ($columns as $column) {
$nameMap[$column->getPhpName()] = $column->getColumnName();
}
self::$phpNameMap = $nameMap;
}
return self::$phpNameMap;
}
/**
* Translates a fieldname to another type
*
* @param string $name field name
* @param string $fromType One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @param string $toType One of the class type constants
* @return string translated name of the field.
*/
static public function translateFieldName($name, $fromType, $toType)
{
$toNames = self::getFieldNames($toType);
$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
if ($key === null) {
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
}
return $toNames[$key];
}
/**
* Returns an array of of field names.
*
* @param string $type The type of fieldnames to return:
* One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return array A list of field names
*/
static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
{
if (!array_key_exists($type, self::$fieldNames)) {
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
}
return self::$fieldNames[$type];
}
/**
* Convenience method which changes table.column to alias.column.
*
* Using this method you can maintain SQL abstraction while using column aliases.
* <code>
* $c->addAlias("alias1", TablePeer::TABLE_NAME);
* $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
* </code>
* @param string $alias The alias for the current table.
* @param string $column The column name for current table. (i.e. ProductOptionsFilterPeer::COLUMN_NAME).
* @return string
*/
public static function alias($alias, $column)
{
return str_replace(ProductOptionsFilterPeer::TABLE_NAME.'.', $alias.'.', $column);
}
/**
* Add all the columns needed to create a new object.
*
* Note: any columns that were marked with lazyLoad="true" in the
* XML schema will not be added to the select list and only loaded
* on demand.
*
* @param criteria object containing the columns to add.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function addSelectColumns(Criteria $criteria)
{
$criteria->addSelectColumn(ProductOptionsFilterPeer::CREATED_AT);
$criteria->addSelectColumn(ProductOptionsFilterPeer::UPDATED_AT);
$criteria->addSelectColumn(ProductOptionsFilterPeer::ID);
$criteria->addSelectColumn(ProductOptionsFilterPeer::OPT_NAME);
$criteria->addSelectColumn(ProductOptionsFilterPeer::FILTER_TYPE);
$criteria->addSelectColumn(ProductOptionsFilterPeer::RANK);
$criteria->addSelectColumn(ProductOptionsFilterPeer::PRICE_FROM);
$criteria->addSelectColumn(ProductOptionsFilterPeer::PRICE_TO);
$criteria->addSelectColumn(ProductOptionsFilterPeer::IS_VISIBLE);
if (stEventDispatcher::getInstance()->getListeners('ProductOptionsFilterPeer.postAddSelectColumns')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'ProductOptionsFilterPeer.postAddSelectColumns'));
}
}
const COUNT = 'COUNT(st_product_options_filter.ID)';
const COUNT_DISTINCT = 'COUNT(DISTINCT st_product_options_filter.ID)';
/**
* Returns the number of rows matching criteria.
*
* @param Criteria $criteria
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCount(Criteria $criteria, $distinct = false, $con = null)
{
// we're going to modify criteria, so copy it first
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsFilterPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsFilterPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$rs = ProductOptionsFilterPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Method to select one object from the DB.
*
* @param Criteria $criteria object used to create the SELECT statement.
* @param Connection $con
* @return ProductOptionsFilter
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectOne(Criteria $criteria, $con = null)
{
$critcopy = clone $criteria;
$critcopy->setLimit(1);
$objects = ProductOptionsFilterPeer::doSelect($critcopy, $con);
if ($objects) {
return $objects[0];
}
return null;
}
/**
* Method to do selects.
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con
* @return ProductOptionsFilter[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelect(Criteria $criteria, $con = null)
{
return ProductOptionsFilterPeer::populateObjects(ProductOptionsFilterPeer::doSelectRS($criteria, $con));
}
/**
* Prepares the Criteria object and uses the parent doSelect()
* method to get a ResultSet.
*
* Use this method directly if you want to just get the resultset
* (instead of an array of objects).
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con the connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return ResultSet The resultset object with numerically-indexed fields.
* @see BasePeer::doSelect()
*/
public static function doSelectRS(Criteria $criteria, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if (!$criteria->getSelectColumns()) {
$criteria = clone $criteria;
ProductOptionsFilterPeer::addSelectColumns($criteria);
}
if (stEventDispatcher::getInstance()->getListeners('BasePeer.preDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'BasePeer.preDoSelectRs'));
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
// BasePeer returns a Creole ResultSet, set to return
// rows indexed numerically.
$rs = BasePeer::doSelect($criteria, $con);
if (stEventDispatcher::getInstance()->getListeners('BasePeer.postDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($rs, 'BasePeer.postDoSelectRs'));
}
return $rs;
}
/**
* The returned array will contain objects of the default type or
* objects that inherit from the default.
*
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function populateObjects(ResultSet $rs)
{
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
// set the class once to avoid overhead in the loop
$cls = ProductOptionsFilterPeer::getOMClass();
$cls = Propel::import($cls);
// populate the object(s)
while($rs->next()) {
$obj = new $cls();
$obj->hydrate($rs);
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj) : $obj;
}
return $results;
}
/**
* Selects a collection of ProductOptionsFilter objects pre-filled with their i18n objects.
*
* @return array Array of ProductOptionsFilter objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectWithI18n(Criteria $c, $culture = null, $con = null)
{
$c = clone $c;
if ($culture === null)
{
$culture = sfContext::getInstance()->getUser()->getCulture();
}
// Set the correct dbName if it has not been overridden
if ($c->getDbName() == Propel::getDefaultDB())
{
$c->setDbName(self::DATABASE_NAME);
}
if (!$c->getSelectColumns())
{
ProductOptionsFilterPeer::addSelectColumns($c);
ProductOptionsFilterI18nPeer::addSelectColumns($c);
}
$c->addJoin(ProductOptionsFilterPeer::ID, sprintf('%s AND %s = \'%s\'', ProductOptionsFilterI18nPeer::ID, ProductOptionsFilterI18nPeer::CULTURE, $culture), Criteria::LEFT_JOIN);
$rs = ProductOptionsFilterPeer::doSelectRs($c, $con);
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
while($rs->next()) {
$obj1 = new ProductOptionsFilter();
$startcol = $obj1->hydrate($rs);
$obj1->setCulture($culture);
$obj2 = new ProductOptionsFilterI18n();
$obj2->hydrate($rs, $startcol);
$obj1->setProductOptionsFilterI18nForCulture($obj2, $culture);
$obj2->setProductOptionsFilter($obj1);
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj1) : $obj1;
}
return $results;
}
/**
* Returns the TableMap related to this peer.
* This method is not needed for general use but a specific application could have a need.
* @return TableMap
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getTableMap()
{
return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
}
/**
* The class that the Peer will make instances of.
*
* This uses a dot-path notation which is tranalted into a path
* relative to a location on the PHP include_path.
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
*
* @return string path.to.ClassName
*/
public static function getOMClass()
{
return ProductOptionsFilterPeer::CLASS_DEFAULT;
}
/**
* Method perform an INSERT on the database, given a ProductOptionsFilter or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsFilter object containing data that is used to create the INSERT statement.
* @param Connection $con the connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsFilterPeer:doInsert:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsFilterPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} else {
$criteria = $values->buildCriteria(); // build Criteria from ProductOptionsFilter object
}
$criteria->remove(ProductOptionsFilterPeer::ID); // remove pkey col since this table uses auto-increment
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->begin();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch(PropelException $e) {
$con->rollback();
throw $e;
}
foreach (sfMixer::getCallables('BaseProductOptionsFilterPeer:doInsert:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsFilterPeer', $values, $con, $pk);
}
return $pk;
}
/**
* Method perform an UPDATE on the database, given a ProductOptionsFilter or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsFilter object containing data that is used to create the UPDATE statement.
* @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
* @return int The number of affected rows (if supported by underlying database driver).
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doUpdate($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsFilterPeer:doUpdate:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsFilterPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$selectCriteria = new Criteria(self::DATABASE_NAME);
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
$comparison = $criteria->getComparison(ProductOptionsFilterPeer::ID);
$selectCriteria->add(ProductOptionsFilterPeer::ID, $criteria->remove(ProductOptionsFilterPeer::ID), $comparison);
} else { // $values is ProductOptionsFilter object
$criteria = $values->buildCriteria(); // gets full criteria
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
}
// set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
foreach (sfMixer::getCallables('BaseProductOptionsFilterPeer:doUpdate:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsFilterPeer', $values, $con, $ret);
}
return $ret;
}
/**
* Method to DELETE all rows from the st_product_options_filter table.
*
* @return int The number of affected rows (if supported by underlying database driver).
*/
public static function doDeleteAll($con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += ProductOptionsFilterPeer::doOnDeleteCascade(new Criteria(), $con);
$affectedRows += BasePeer::doDeleteAll(ProductOptionsFilterPeer::TABLE_NAME, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Method perform a DELETE on the database, given a ProductOptionsFilter or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ProductOptionsFilter object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param Connection $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doDelete($values, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(ProductOptionsFilterPeer::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} elseif ($values instanceof ProductOptionsFilter) {
$criteria = $values->buildPkeyCriteria();
} else {
// it must be the primary key
$criteria = new Criteria(self::DATABASE_NAME);
$criteria->add(ProductOptionsFilterPeer::ID, (array) $values, Criteria::IN);
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += ProductOptionsFilterPeer::doOnDeleteCascade($criteria, $con);
$affectedRows += BasePeer::doDelete($criteria, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* This is a method for emulating ON DELETE CASCADE for DBs that don't support this
* feature (like MySQL or SQLite).
*
* This method is not very speedy because it must perform a query first to get
* the implicated records and then perform the deletes by calling those Peer classes.
*
* This method should be used within a transaction if possible.
*
* @param Criteria $criteria
* @param Connection $con
* @return int The number of affected rows (if supported by underlying database driver).
*/
protected static function doOnDeleteCascade(Criteria $criteria, Connection $con)
{
// initialize var to track total num of affected rows
$affectedRows = 0;
// first find the objects that are implicated by the $criteria
$objects = ProductOptionsFilterPeer::doSelect($criteria, $con);
foreach($objects as $obj) {
// delete related ProductOptionsFilterI18n objects
$c = new Criteria();
$c->add(ProductOptionsFilterI18nPeer::ID, $obj->getId());
$affectedRows += ProductOptionsFilterI18nPeer::doDelete($c, $con);
}
return $affectedRows;
}
/**
* Validates all modified columns of given ProductOptionsFilter object.
* If parameter $columns is either a single column name or an array of column names
* than only those columns are validated.
*
* NOTICE: This does not apply to primary or foreign keys for now.
*
* @param ProductOptionsFilter $obj The object to validate.
* @param mixed $cols Column name or array of column names.
*
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
*/
public static function doValidate(ProductOptionsFilter $obj, $cols = null)
{
$columns = array();
if ($cols) {
$dbMap = Propel::getDatabaseMap(ProductOptionsFilterPeer::DATABASE_NAME);
$tableMap = $dbMap->getTable(ProductOptionsFilterPeer::TABLE_NAME);
if (! is_array($cols)) {
$cols = array($cols);
}
foreach($cols as $colName) {
if ($tableMap->containsColumn($colName)) {
$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
$columns[$colName] = $obj->$get();
}
}
} else {
}
$res = BasePeer::doValidate(ProductOptionsFilterPeer::DATABASE_NAME, ProductOptionsFilterPeer::TABLE_NAME, $columns);
if ($res !== true) {
$request = sfContext::getInstance()->getRequest();
foreach ($res as $failed) {
$col = ProductOptionsFilterPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
$request->setError($col, $failed->getMessage());
}
}
return $res;
}
/**
* Retrieve a single object by pkey.
*
* @param mixed $pk the primary key.
* @param Connection $con the connection to use
* @return ProductOptionsFilter
*/
public static function retrieveByPK($pk, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$criteria = new Criteria(ProductOptionsFilterPeer::DATABASE_NAME);
$criteria->add(ProductOptionsFilterPeer::ID, $pk);
$v = ProductOptionsFilterPeer::doSelect($criteria, $con);
return !empty($v) > 0 ? $v[0] : null;
}
/**
* Retrieve multiple objects by pkey.
*
* @param array $pks List of primary keys
* @param Connection $con the connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return ProductOptionsFilter[]
*/
public static function retrieveByPKs($pks, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$objs = null;
if (empty($pks)) {
$objs = array();
} else {
$criteria = new Criteria();
$criteria->add(ProductOptionsFilterPeer::ID, $pks, Criteria::IN);
$objs = ProductOptionsFilterPeer::doSelect($criteria, $con);
}
return $objs;
}
} // BaseProductOptionsFilterPeer
// static code to register the map builder for this Peer with the main Propel class
if (Propel::isInit()) {
// the MapBuilder classes register themselves with Propel during initialization
// so we need to load them here.
try {
BaseProductOptionsFilterPeer::getMapBuilder();
} catch (Exception $e) {
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
}
} else {
// even if Propel is not yet initialized, the map builder class can be registered
// now and then it will be loaded when Propel initializes.
Propel::registerMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsFilterMapBuilder');
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,693 @@
<?php
/**
* Base static class for performing query and update operations on the 'st_product_options_template' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model.om
*/
abstract class BaseProductOptionsTemplatePeer {
/** the default database name for this class */
const DATABASE_NAME = 'propel';
/** the table name for this class */
const TABLE_NAME = 'st_product_options_template';
/** A class that can be returned by this peer. */
const CLASS_DEFAULT = 'plugins.stProductOptionsPlugin.lib.model.ProductOptionsTemplate';
/** The total number of columns. */
const NUM_COLUMNS = 4;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
/** the column name for the CREATED_AT field */
const CREATED_AT = 'st_product_options_template.CREATED_AT';
/** the column name for the UPDATED_AT field */
const UPDATED_AT = 'st_product_options_template.UPDATED_AT';
/** the column name for the ID field */
const ID = 'st_product_options_template.ID';
/** the column name for the OPT_NAME field */
const OPT_NAME = 'st_product_options_template.OPT_NAME';
/** The PHP to DB Name Mapping */
private static $phpNameMap = null;
/**
* holds an array of fieldnames
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('CreatedAt', 'UpdatedAt', 'Id', 'OptName', ),
BasePeer::TYPE_COLNAME => array (ProductOptionsTemplatePeer::CREATED_AT, ProductOptionsTemplatePeer::UPDATED_AT, ProductOptionsTemplatePeer::ID, ProductOptionsTemplatePeer::OPT_NAME, ),
BasePeer::TYPE_FIELDNAME => array ('created_at', 'updated_at', 'id', 'opt_name', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
);
/**
* holds an array of keys for quick access to the fieldnames array
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('CreatedAt' => 0, 'UpdatedAt' => 1, 'Id' => 2, 'OptName' => 3, ),
BasePeer::TYPE_COLNAME => array (ProductOptionsTemplatePeer::CREATED_AT => 0, ProductOptionsTemplatePeer::UPDATED_AT => 1, ProductOptionsTemplatePeer::ID => 2, ProductOptionsTemplatePeer::OPT_NAME => 3, ),
BasePeer::TYPE_FIELDNAME => array ('created_at' => 0, 'updated_at' => 1, 'id' => 2, 'opt_name' => 3, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
);
protected static $hydrateMethod = null;
protected static $postHydrateMethod = null;
public static function setHydrateMethod($callback)
{
self::$hydrateMethod = $callback;
}
public static function setPostHydrateMethod($callback)
{
self::$postHydrateMethod = $callback;
}
/**
* @return MapBuilder the map builder for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getMapBuilder()
{
return BasePeer::getMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsTemplateMapBuilder');
}
/**
* Gets a map (hash) of PHP names to DB column names.
*
* @return array The PHP to DB name map for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
*/
public static function getPhpNameMap()
{
if (self::$phpNameMap === null) {
$map = ProductOptionsTemplatePeer::getTableMap();
$columns = $map->getColumns();
$nameMap = array();
foreach ($columns as $column) {
$nameMap[$column->getPhpName()] = $column->getColumnName();
}
self::$phpNameMap = $nameMap;
}
return self::$phpNameMap;
}
/**
* Translates a fieldname to another type
*
* @param string $name field name
* @param string $fromType One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @param string $toType One of the class type constants
* @return string translated name of the field.
*/
static public function translateFieldName($name, $fromType, $toType)
{
$toNames = self::getFieldNames($toType);
$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
if ($key === null) {
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
}
return $toNames[$key];
}
/**
* Returns an array of of field names.
*
* @param string $type The type of fieldnames to return:
* One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return array A list of field names
*/
static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
{
if (!array_key_exists($type, self::$fieldNames)) {
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
}
return self::$fieldNames[$type];
}
/**
* Convenience method which changes table.column to alias.column.
*
* Using this method you can maintain SQL abstraction while using column aliases.
* <code>
* $c->addAlias("alias1", TablePeer::TABLE_NAME);
* $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
* </code>
* @param string $alias The alias for the current table.
* @param string $column The column name for current table. (i.e. ProductOptionsTemplatePeer::COLUMN_NAME).
* @return string
*/
public static function alias($alias, $column)
{
return str_replace(ProductOptionsTemplatePeer::TABLE_NAME.'.', $alias.'.', $column);
}
/**
* Add all the columns needed to create a new object.
*
* Note: any columns that were marked with lazyLoad="true" in the
* XML schema will not be added to the select list and only loaded
* on demand.
*
* @param criteria object containing the columns to add.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function addSelectColumns(Criteria $criteria)
{
$criteria->addSelectColumn(ProductOptionsTemplatePeer::CREATED_AT);
$criteria->addSelectColumn(ProductOptionsTemplatePeer::UPDATED_AT);
$criteria->addSelectColumn(ProductOptionsTemplatePeer::ID);
$criteria->addSelectColumn(ProductOptionsTemplatePeer::OPT_NAME);
if (stEventDispatcher::getInstance()->getListeners('ProductOptionsTemplatePeer.postAddSelectColumns')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'ProductOptionsTemplatePeer.postAddSelectColumns'));
}
}
const COUNT = 'COUNT(st_product_options_template.ID)';
const COUNT_DISTINCT = 'COUNT(DISTINCT st_product_options_template.ID)';
/**
* Returns the number of rows matching criteria.
*
* @param Criteria $criteria
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCount(Criteria $criteria, $distinct = false, $con = null)
{
// we're going to modify criteria, so copy it first
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsTemplatePeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsTemplatePeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$rs = ProductOptionsTemplatePeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Method to select one object from the DB.
*
* @param Criteria $criteria object used to create the SELECT statement.
* @param Connection $con
* @return ProductOptionsTemplate
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectOne(Criteria $criteria, $con = null)
{
$critcopy = clone $criteria;
$critcopy->setLimit(1);
$objects = ProductOptionsTemplatePeer::doSelect($critcopy, $con);
if ($objects) {
return $objects[0];
}
return null;
}
/**
* Method to do selects.
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con
* @return ProductOptionsTemplate[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelect(Criteria $criteria, $con = null)
{
return ProductOptionsTemplatePeer::populateObjects(ProductOptionsTemplatePeer::doSelectRS($criteria, $con));
}
/**
* Prepares the Criteria object and uses the parent doSelect()
* method to get a ResultSet.
*
* Use this method directly if you want to just get the resultset
* (instead of an array of objects).
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con the connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return ResultSet The resultset object with numerically-indexed fields.
* @see BasePeer::doSelect()
*/
public static function doSelectRS(Criteria $criteria, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if (!$criteria->getSelectColumns()) {
$criteria = clone $criteria;
ProductOptionsTemplatePeer::addSelectColumns($criteria);
}
if (stEventDispatcher::getInstance()->getListeners('BasePeer.preDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'BasePeer.preDoSelectRs'));
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
// BasePeer returns a Creole ResultSet, set to return
// rows indexed numerically.
$rs = BasePeer::doSelect($criteria, $con);
if (stEventDispatcher::getInstance()->getListeners('BasePeer.postDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($rs, 'BasePeer.postDoSelectRs'));
}
return $rs;
}
/**
* The returned array will contain objects of the default type or
* objects that inherit from the default.
*
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function populateObjects(ResultSet $rs)
{
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
// set the class once to avoid overhead in the loop
$cls = ProductOptionsTemplatePeer::getOMClass();
$cls = Propel::import($cls);
// populate the object(s)
while($rs->next()) {
$obj = new $cls();
$obj->hydrate($rs);
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj) : $obj;
}
return $results;
}
/**
* Returns the TableMap related to this peer.
* This method is not needed for general use but a specific application could have a need.
* @return TableMap
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getTableMap()
{
return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
}
/**
* The class that the Peer will make instances of.
*
* This uses a dot-path notation which is tranalted into a path
* relative to a location on the PHP include_path.
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
*
* @return string path.to.ClassName
*/
public static function getOMClass()
{
return ProductOptionsTemplatePeer::CLASS_DEFAULT;
}
/**
* Method perform an INSERT on the database, given a ProductOptionsTemplate or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsTemplate object containing data that is used to create the INSERT statement.
* @param Connection $con the connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsTemplatePeer:doInsert:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsTemplatePeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} else {
$criteria = $values->buildCriteria(); // build Criteria from ProductOptionsTemplate object
}
$criteria->remove(ProductOptionsTemplatePeer::ID); // remove pkey col since this table uses auto-increment
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->begin();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch(PropelException $e) {
$con->rollback();
throw $e;
}
foreach (sfMixer::getCallables('BaseProductOptionsTemplatePeer:doInsert:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsTemplatePeer', $values, $con, $pk);
}
return $pk;
}
/**
* Method perform an UPDATE on the database, given a ProductOptionsTemplate or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsTemplate object containing data that is used to create the UPDATE statement.
* @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
* @return int The number of affected rows (if supported by underlying database driver).
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doUpdate($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsTemplatePeer:doUpdate:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsTemplatePeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$selectCriteria = new Criteria(self::DATABASE_NAME);
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
$comparison = $criteria->getComparison(ProductOptionsTemplatePeer::ID);
$selectCriteria->add(ProductOptionsTemplatePeer::ID, $criteria->remove(ProductOptionsTemplatePeer::ID), $comparison);
} else { // $values is ProductOptionsTemplate object
$criteria = $values->buildCriteria(); // gets full criteria
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
}
// set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
foreach (sfMixer::getCallables('BaseProductOptionsTemplatePeer:doUpdate:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsTemplatePeer', $values, $con, $ret);
}
return $ret;
}
/**
* Method to DELETE all rows from the st_product_options_template table.
*
* @return int The number of affected rows (if supported by underlying database driver).
*/
public static function doDeleteAll($con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += ProductOptionsTemplatePeer::doOnDeleteCascade(new Criteria(), $con);
$affectedRows += BasePeer::doDeleteAll(ProductOptionsTemplatePeer::TABLE_NAME, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Method perform a DELETE on the database, given a ProductOptionsTemplate or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ProductOptionsTemplate object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param Connection $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doDelete($values, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(ProductOptionsTemplatePeer::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} elseif ($values instanceof ProductOptionsTemplate) {
$criteria = $values->buildPkeyCriteria();
} else {
// it must be the primary key
$criteria = new Criteria(self::DATABASE_NAME);
$criteria->add(ProductOptionsTemplatePeer::ID, (array) $values, Criteria::IN);
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += ProductOptionsTemplatePeer::doOnDeleteCascade($criteria, $con);
$affectedRows += BasePeer::doDelete($criteria, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* This is a method for emulating ON DELETE CASCADE for DBs that don't support this
* feature (like MySQL or SQLite).
*
* This method is not very speedy because it must perform a query first to get
* the implicated records and then perform the deletes by calling those Peer classes.
*
* This method should be used within a transaction if possible.
*
* @param Criteria $criteria
* @param Connection $con
* @return int The number of affected rows (if supported by underlying database driver).
*/
protected static function doOnDeleteCascade(Criteria $criteria, Connection $con)
{
// initialize var to track total num of affected rows
$affectedRows = 0;
// first find the objects that are implicated by the $criteria
$objects = ProductOptionsTemplatePeer::doSelect($criteria, $con);
foreach($objects as $obj) {
// delete related ProductOptionsField objects
$c = new Criteria();
$c->add(ProductOptionsFieldPeer::PRODUCT_OPTIONS_TEMPLATE_ID, $obj->getId());
$affectedRows += ProductOptionsFieldPeer::doDelete($c, $con);
// delete related ProductOptionsDefaultValue objects
$c = new Criteria();
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_TEMPLATE_ID, $obj->getId());
$affectedRows += ProductOptionsDefaultValuePeer::doDelete($c, $con);
}
return $affectedRows;
}
/**
* Validates all modified columns of given ProductOptionsTemplate object.
* If parameter $columns is either a single column name or an array of column names
* than only those columns are validated.
*
* NOTICE: This does not apply to primary or foreign keys for now.
*
* @param ProductOptionsTemplate $obj The object to validate.
* @param mixed $cols Column name or array of column names.
*
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
*/
public static function doValidate(ProductOptionsTemplate $obj, $cols = null)
{
$columns = array();
if ($cols) {
$dbMap = Propel::getDatabaseMap(ProductOptionsTemplatePeer::DATABASE_NAME);
$tableMap = $dbMap->getTable(ProductOptionsTemplatePeer::TABLE_NAME);
if (! is_array($cols)) {
$cols = array($cols);
}
foreach($cols as $colName) {
if ($tableMap->containsColumn($colName)) {
$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
$columns[$colName] = $obj->$get();
}
}
} else {
}
$res = BasePeer::doValidate(ProductOptionsTemplatePeer::DATABASE_NAME, ProductOptionsTemplatePeer::TABLE_NAME, $columns);
if ($res !== true) {
$request = sfContext::getInstance()->getRequest();
foreach ($res as $failed) {
$col = ProductOptionsTemplatePeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
$request->setError($col, $failed->getMessage());
}
}
return $res;
}
/**
* Retrieve a single object by pkey.
*
* @param mixed $pk the primary key.
* @param Connection $con the connection to use
* @return ProductOptionsTemplate
*/
public static function retrieveByPK($pk, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$criteria = new Criteria(ProductOptionsTemplatePeer::DATABASE_NAME);
$criteria->add(ProductOptionsTemplatePeer::ID, $pk);
$v = ProductOptionsTemplatePeer::doSelect($criteria, $con);
return !empty($v) > 0 ? $v[0] : null;
}
/**
* Retrieve multiple objects by pkey.
*
* @param array $pks List of primary keys
* @param Connection $con the connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return ProductOptionsTemplate[]
*/
public static function retrieveByPKs($pks, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$objs = null;
if (empty($pks)) {
$objs = array();
} else {
$criteria = new Criteria();
$criteria->add(ProductOptionsTemplatePeer::ID, $pks, Criteria::IN);
$objs = ProductOptionsTemplatePeer::doSelect($criteria, $con);
}
return $objs;
}
} // BaseProductOptionsTemplatePeer
// static code to register the map builder for this Peer with the main Propel class
if (Propel::isInit()) {
// the MapBuilder classes register themselves with Propel during initialization
// so we need to load them here.
try {
BaseProductOptionsTemplatePeer::getMapBuilder();
} catch (Exception $e) {
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
}
} else {
// even if Propel is not yet initialized, the map builder class can be registered
// now and then it will be loaded when Propel initializes.
Propel::registerMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsTemplateMapBuilder');
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,776 @@
<?php
/**
* Base class that represents a row from the 'st_product_options_value_i18n' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model.om
*/
abstract class BaseProductOptionsValueI18n extends BaseObject implements Persistent {
protected static $dispatcher = null;
/**
* The value for the id field.
* @var int
*/
protected $id;
/**
* The value for the culture field.
* @var string
*/
protected $culture;
/**
* The value for the value field.
* @var string
*/
protected $value;
/**
* @var ProductOptionsValue
*/
protected $aProductOptionsValue;
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
* @var boolean
*/
protected $alreadyInSave = false;
/**
* Flag to prevent endless validation loop, if this object is referenced
* by another object which falls in this transaction.
* @var boolean
*/
protected $alreadyInValidation = false;
/**
* Get the [id] column value.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Get the [culture] column value.
*
* @return string
*/
public function getCulture()
{
return $this->culture;
}
/**
* Get the [value] column value.
*
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* Set the value of [id] column.
*
* @param int $v new value
* @return void
*/
public function setId($v)
{
if ($v !== null && !is_int($v) && is_numeric($v)) {
$v = (int) $v;
}
if ($this->id !== $v) {
$this->id = $v;
$this->modifiedColumns[] = ProductOptionsValueI18nPeer::ID;
}
if ($this->aProductOptionsValue !== null && $this->aProductOptionsValue->getId() !== $v) {
$this->aProductOptionsValue = null;
}
} // setId()
/**
* Set the value of [culture] column.
*
* @param string $v new value
* @return void
*/
public function setCulture($v)
{
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->culture !== $v) {
$this->culture = $v;
$this->modifiedColumns[] = ProductOptionsValueI18nPeer::CULTURE;
}
} // setCulture()
/**
* Set the value of [value] column.
*
* @param string $v new value
* @return void
*/
public function setValue($v)
{
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->value !== $v) {
$this->value = $v;
$this->modifiedColumns[] = ProductOptionsValueI18nPeer::VALUE;
}
} // setValue()
/**
* Hydrates (populates) the object variables with values from the database resultset.
*
* An offset (1-based "start column") is specified so that objects can be hydrated
* with a subset of the columns in the resultset rows. This is needed, for example,
* for results of JOIN queries where the resultset row includes columns from two or
* more tables.
*
* @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos.
* @param int $startcol 1-based offset column which indicates which restultset column to start with.
* @return int next starting column
* @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
*/
public function hydrate(ResultSet $rs, $startcol = 1)
{
try {
if ($this->getDispatcher()->getListeners('ProductOptionsValueI18n.preHydrate')) {
$event = $this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsValueI18n.preHydrate', array('resultset' => $rs, 'startcol' => $startcol)));
$startcol = $event['startcol'];
}
$this->id = $rs->getInt($startcol + 0);
$this->culture = $rs->getString($startcol + 1);
$this->value = $rs->getString($startcol + 2);
$this->resetModified();
$this->setNew(false);
if ($this->getDispatcher()->getListeners('ProductOptionsValueI18n.postHydrate')) {
$event = $this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsValueI18n.postHydrate', array('resultset' => $rs, 'startcol' => $startcol + 3)));
return $event['startcol'];
}
// FIXME - using NUM_COLUMNS may be clearer.
return $startcol + 3; // 3 = ProductOptionsValueI18nPeer::NUM_COLUMNS - ProductOptionsValueI18nPeer::NUM_LAZY_LOAD_COLUMNS).
} catch (Exception $e) {
throw new PropelException("Error populating ProductOptionsValueI18n object", $e);
}
}
/**
* Removes this object from datastore and sets delete attribute.
*
* @param Connection $con
* @return void
* @throws PropelException
* @see BaseObject::setDeleted()
* @see BaseObject::isDeleted()
*/
public function delete($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("This object has already been deleted.");
}
if ($this->getDispatcher()->getListeners('ProductOptionsValueI18n.preDelete')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsValueI18n.preDelete', array('con' => $con)));
}
if (sfMixer::hasCallables('BaseProductOptionsValueI18n:delete:pre'))
{
foreach (sfMixer::getCallables('BaseProductOptionsValueI18n:delete:pre') as $callable)
{
$ret = call_user_func($callable, $this, $con);
if ($ret)
{
return;
}
}
}
if ($con === null) {
$con = Propel::getConnection(ProductOptionsValueI18nPeer::DATABASE_NAME);
}
try {
$con->begin();
ProductOptionsValueI18nPeer::doDelete($this, $con);
$this->setDeleted(true);
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
if ($this->getDispatcher()->getListeners('ProductOptionsValueI18n.postDelete')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsValueI18n.postDelete', array('con' => $con)));
}
if (sfMixer::hasCallables('BaseProductOptionsValueI18n:delete:post'))
{
foreach (sfMixer::getCallables('BaseProductOptionsValueI18n:delete:post') as $callable)
{
call_user_func($callable, $this, $con);
}
}
}
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed. This method
* wraps the doSave() worker method in a transaction.
*
* @param Connection $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see doSave()
*/
public function save($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("You cannot save an object that has been deleted.");
}
if (!$this->alreadyInSave) {
if ($this->getDispatcher()->getListeners('ProductOptionsValueI18n.preSave')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsValueI18n.preSave', array('con' => $con)));
}
foreach (sfMixer::getCallables('BaseProductOptionsValueI18n:save:pre') as $callable)
{
$affectedRows = call_user_func($callable, $this, $con);
if (is_int($affectedRows))
{
return $affectedRows;
}
}
}
if ($con === null) {
$con = Propel::getConnection(ProductOptionsValueI18nPeer::DATABASE_NAME);
}
try {
$con->begin();
$affectedRows = $this->doSave($con);
$con->commit();
if (!$this->alreadyInSave) {
if ($this->getDispatcher()->getListeners('ProductOptionsValueI18n.postSave')) {
$this->getDispatcher()->notify(new sfEvent($this, 'ProductOptionsValueI18n.postSave', array('con' => $con)));
}
foreach (sfMixer::getCallables('BaseProductOptionsValueI18n:save:post') as $callable)
{
call_user_func($callable, $this, $con, $affectedRows);
}
}
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Stores the object in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param Connection $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave($con)
{
$affectedRows = 0; // initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aProductOptionsValue !== null) {
if ($this->aProductOptionsValue->isModified() || $this->aProductOptionsValue->getCurrentProductOptionsValueI18n()->isModified()) {
$affectedRows += $this->aProductOptionsValue->save($con);
}
$this->setProductOptionsValue($this->aProductOptionsValue);
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = ProductOptionsValueI18nPeer::doInsert($this, $con);
$affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setNew(false);
} else {
$affectedRows += ProductOptionsValueI18nPeer::doUpdate($this, $con);
}
$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
} // doSave()
/**
* Array of ValidationFailed objects.
* @var array ValidationFailed[]
*/
protected $validationFailures = array();
/**
* Gets any ValidationFailed objects that resulted from last call to validate().
*
*
* @return array ValidationFailed[]
* @see validate()
*/
public function getValidationFailures()
{
return $this->validationFailures;
}
/**
* Validates the objects modified field values and all objects related to this table.
*
* If $columns is either a column name or an array of column names
* only those columns are validated.
*
* @param mixed $columns Column name or an array of column names.
* @return boolean Whether all columns pass validation.
* @see doValidate()
* @see getValidationFailures()
*/
public function validate($columns = null)
{
$res = $this->doValidate($columns);
if ($res === true) {
$this->validationFailures = array();
return true;
} else {
$this->validationFailures = $res;
return false;
}
}
/**
* This function performs the validation work for complex object models.
*
* In addition to checking the current object, all related objects will
* also be validated. If all pass then <code>true</code> is returned; otherwise
* an aggreagated array of ValidationFailed objects will be returned.
*
* @param array $columns Array of column names to validate.
* @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
*/
protected function doValidate($columns = null)
{
if (!$this->alreadyInValidation) {
$this->alreadyInValidation = true;
$retval = null;
$failureMap = array();
// We call the validate method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aProductOptionsValue !== null) {
if (!$this->aProductOptionsValue->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aProductOptionsValue->getValidationFailures());
}
}
if (($retval = ProductOptionsValueI18nPeer::doValidate($this, $columns)) !== true) {
$failureMap = array_merge($failureMap, $retval);
}
$this->alreadyInValidation = false;
}
return (!empty($failureMap) ? $failureMap : true);
}
/**
* Retrieves a field from the object by name passed in as a string.
*
* @param string $name name
* @param string $type The type of fieldname the $name is of:
* one of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return mixed Value of field.
*/
public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
{
$pos = ProductOptionsValueI18nPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
return $this->getByPosition($pos);
}
/**
* Retrieves a field from the object by Position as specified in the xml schema.
* Zero-based.
*
* @param int $pos position in xml schema
* @return mixed Value of field at $pos
*/
public function getByPosition($pos)
{
switch($pos) {
case 0:
return $this->getId();
break;
case 1:
return $this->getCulture();
break;
case 2:
return $this->getValue();
break;
default:
return null;
break;
} // switch()
}
/**
* Exports the object as an array.
*
* You can specify the key type of the array by passing one of the class
* type constants.
*
* @param string $keyType One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return an associative array containing the field names (as keys) and field values
*/
public function toArray($keyType = BasePeer::TYPE_PHPNAME)
{
$keys = ProductOptionsValueI18nPeer::getFieldNames($keyType);
$result = array(
$keys[0] => $this->getId(),
$keys[1] => $this->getCulture(),
$keys[2] => $this->getValue(),
);
return $result;
}
/**
* Sets a field from the object by name passed in as a string.
*
* @param string $name peer name
* @param mixed $value field value
* @param string $type The type of fieldname the $name is of:
* one of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return void
*/
public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
{
$pos = ProductOptionsValueI18nPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
return $this->setByPosition($pos, $value);
}
/**
* Sets a field from the object by Position as specified in the xml schema.
* Zero-based.
*
* @param int $pos position in xml schema
* @param mixed $value field value
* @return void
*/
public function setByPosition($pos, $value)
{
switch($pos) {
case 0:
$this->setId($value);
break;
case 1:
$this->setCulture($value);
break;
case 2:
$this->setValue($value);
break;
} // switch()
}
/**
* Populates the object using an array.
*
* This is particularly useful when populating an object from one of the
* request arrays (e.g. $_POST). This method goes through the column
* names, checking to see whether a matching key exists in populated
* array. If so the setByName() method is called for that column.
*
* You can specify the key type of the array by additionally passing one
* of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
* TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
*
* @param array $arr An array to populate the object from.
* @param string $keyType The type of keys the array uses.
* @return void
*/
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
{
$keys = ProductOptionsValueI18nPeer::getFieldNames($keyType);
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
if (array_key_exists($keys[1], $arr)) $this->setCulture($arr[$keys[1]]);
if (array_key_exists($keys[2], $arr)) $this->setValue($arr[$keys[2]]);
}
/**
* Build a Criteria object containing the values of all modified columns in this object.
*
* @return Criteria The Criteria object containing all modified values.
*/
public function buildCriteria()
{
$criteria = new Criteria(ProductOptionsValueI18nPeer::DATABASE_NAME);
if ($this->isColumnModified(ProductOptionsValueI18nPeer::ID)) $criteria->add(ProductOptionsValueI18nPeer::ID, $this->id);
if ($this->isColumnModified(ProductOptionsValueI18nPeer::CULTURE)) $criteria->add(ProductOptionsValueI18nPeer::CULTURE, $this->culture);
if ($this->isColumnModified(ProductOptionsValueI18nPeer::VALUE)) $criteria->add(ProductOptionsValueI18nPeer::VALUE, $this->value);
return $criteria;
}
/**
* Builds a Criteria object containing the primary key for this object.
*
* Unlike buildCriteria() this method includes the primary key values regardless
* of whether or not they have been modified.
*
* @return Criteria The Criteria object containing value(s) for primary key(s).
*/
public function buildPkeyCriteria()
{
$criteria = new Criteria(ProductOptionsValueI18nPeer::DATABASE_NAME);
$criteria->add(ProductOptionsValueI18nPeer::ID, $this->id);
$criteria->add(ProductOptionsValueI18nPeer::CULTURE, $this->culture);
return $criteria;
}
/**
* Returns the composite primary key for this object.
* The array elements will be in same order as specified in XML.
* @return array
*/
public function getPrimaryKey()
{
return array($this->getId(), $this->getCulture());
}
/**
* Returns [composite] primary key fields
*
* @param string $keyType
* @return array
*/
public function getPrimaryKeyFields($keyType = BasePeer::TYPE_FIELDNAME)
{
return array(ProductOptionsValueI18nPeer::translateFieldName('id', BasePeer::TYPE_FIELDNAME, $keyType), ProductOptionsValueI18nPeer::translateFieldName('culture', BasePeer::TYPE_FIELDNAME, $keyType));
}
/**
* Set the [composite] primary key.
*
* @param array $keys The elements of the composite key (order must match the order in XML file).
* @return void
*/
public function setPrimaryKey($keys)
{
$this->setId($keys[0]);
$this->setCulture($keys[1]);
}
/**
* Sets contents of passed object to values from current object.
*
* If desired, this method can also make copies of all associated (fkey referrers)
* objects.
*
* @param object $copyObj An object of ProductOptionsValueI18n (or compatible) type.
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
* @throws PropelException
*/
public function copyInto($copyObj, $deepCopy = false)
{
$copyObj->setValue($this->value);
$copyObj->setNew(true);
$copyObj->setId(NULL); // this is a pkey column, so set to default value
$copyObj->setCulture(NULL); // this is a pkey column, so set to default value
}
/**
* Makes a copy of this object that will be inserted as a new row in table when saved.
* It creates a new object filling in the simple attributes, but skipping any primary
* keys that are defined for the table.
*
* If desired, this method can also make copies of all associated (fkey referrers)
* objects.
*
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
* @return ProductOptionsValueI18n Clone of current object.
* @throws PropelException
*/
public function copy($deepCopy = false)
{
// we use get_class(), because this might be a subclass
$clazz = get_class($this);
$copyObj = new $clazz();
$this->copyInto($copyObj, $deepCopy);
return $copyObj;
}
/**
* Returns a peer instance associated with this om.
*
* @return string Peer class name
*/
public function getPeer()
{
return 'ProductOptionsValueI18nPeer';
}
/**
* Declares an association between this object and a ProductOptionsValue object.
*
* @param ProductOptionsValue $v
* @return void
* @throws PropelException
*/
public function setProductOptionsValue($v)
{
if ($v === null) {
$this->setId(NULL);
} else {
$this->setId($v->getId());
}
$this->aProductOptionsValue = $v;
}
/**
* Get the associated ProductOptionsValue object
*
* @param Connection Optional Connection object.
* @return ProductOptionsValue The associated ProductOptionsValue object.
* @throws PropelException
*/
public function getProductOptionsValue($con = null)
{
if ($this->aProductOptionsValue === null && ($this->id !== null)) {
// include the related Peer class
$this->aProductOptionsValue = ProductOptionsValuePeer::retrieveByPK($this->id, $con);
/* The following can be used instead of the line above to
guarantee the related object contains a reference
to this object, but this level of coupling
may be undesirable in many circumstances.
As it can lead to a db query with many results that may
never be used.
$obj = ProductOptionsValuePeer::retrieveByPK($this->id, $con);
$obj->addProductOptionsValues($this);
*/
}
return $this->aProductOptionsValue;
}
public function getDispatcher()
{
if (null === self::$dispatcher)
{
self::$dispatcher = stEventDispatcher::getInstance();
}
return self::$dispatcher;
}
public function __call($method, $arguments)
{
$event = $this->getDispatcher()->notifyUntil(new sfEvent($this, 'ProductOptionsValueI18n.' . $method, array('arguments' => $arguments, 'method' => $method)));
if ($event->isProcessed())
{
return $event->getReturnValue();
}
if (!$callable = sfMixer::getCallable('BaseProductOptionsValueI18n:'.$method))
{
throw new sfException(sprintf('Call to undefined method BaseProductOptionsValueI18n::%s', $method));
}
array_unshift($arguments, $this);
return call_user_func_array($callable, $arguments);
}
} // BaseProductOptionsValueI18n

View File

@@ -0,0 +1,834 @@
<?php
/**
* Base static class for performing query and update operations on the 'st_product_options_value_i18n' table.
*
*
*
* @package plugins.stProductOptionsPlugin.lib.model.om
*/
abstract class BaseProductOptionsValueI18nPeer {
/** the default database name for this class */
const DATABASE_NAME = 'propel';
/** the table name for this class */
const TABLE_NAME = 'st_product_options_value_i18n';
/** A class that can be returned by this peer. */
const CLASS_DEFAULT = 'plugins.stProductOptionsPlugin.lib.model.ProductOptionsValueI18n';
/** The total number of columns. */
const NUM_COLUMNS = 3;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
/** the column name for the ID field */
const ID = 'st_product_options_value_i18n.ID';
/** the column name for the CULTURE field */
const CULTURE = 'st_product_options_value_i18n.CULTURE';
/** the column name for the VALUE field */
const VALUE = 'st_product_options_value_i18n.VALUE';
/** The PHP to DB Name Mapping */
private static $phpNameMap = null;
/**
* holds an array of fieldnames
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('Id', 'Culture', 'Value', ),
BasePeer::TYPE_COLNAME => array (ProductOptionsValueI18nPeer::ID, ProductOptionsValueI18nPeer::CULTURE, ProductOptionsValueI18nPeer::VALUE, ),
BasePeer::TYPE_FIELDNAME => array ('id', 'culture', 'value', ),
BasePeer::TYPE_NUM => array (0, 1, 2, )
);
/**
* holds an array of keys for quick access to the fieldnames array
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Culture' => 1, 'Value' => 2, ),
BasePeer::TYPE_COLNAME => array (ProductOptionsValueI18nPeer::ID => 0, ProductOptionsValueI18nPeer::CULTURE => 1, ProductOptionsValueI18nPeer::VALUE => 2, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'culture' => 1, 'value' => 2, ),
BasePeer::TYPE_NUM => array (0, 1, 2, )
);
protected static $hydrateMethod = null;
protected static $postHydrateMethod = null;
public static function setHydrateMethod($callback)
{
self::$hydrateMethod = $callback;
}
public static function setPostHydrateMethod($callback)
{
self::$postHydrateMethod = $callback;
}
/**
* @return MapBuilder the map builder for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getMapBuilder()
{
return BasePeer::getMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsValueI18nMapBuilder');
}
/**
* Gets a map (hash) of PHP names to DB column names.
*
* @return array The PHP to DB name map for this peer
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
*/
public static function getPhpNameMap()
{
if (self::$phpNameMap === null) {
$map = ProductOptionsValueI18nPeer::getTableMap();
$columns = $map->getColumns();
$nameMap = array();
foreach ($columns as $column) {
$nameMap[$column->getPhpName()] = $column->getColumnName();
}
self::$phpNameMap = $nameMap;
}
return self::$phpNameMap;
}
/**
* Translates a fieldname to another type
*
* @param string $name field name
* @param string $fromType One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @param string $toType One of the class type constants
* @return string translated name of the field.
*/
static public function translateFieldName($name, $fromType, $toType)
{
$toNames = self::getFieldNames($toType);
$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
if ($key === null) {
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
}
return $toNames[$key];
}
/**
* Returns an array of of field names.
*
* @param string $type The type of fieldnames to return:
* One of the class type constants TYPE_PHPNAME,
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
* @return array A list of field names
*/
static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
{
if (!array_key_exists($type, self::$fieldNames)) {
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
}
return self::$fieldNames[$type];
}
/**
* Convenience method which changes table.column to alias.column.
*
* Using this method you can maintain SQL abstraction while using column aliases.
* <code>
* $c->addAlias("alias1", TablePeer::TABLE_NAME);
* $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
* </code>
* @param string $alias The alias for the current table.
* @param string $column The column name for current table. (i.e. ProductOptionsValueI18nPeer::COLUMN_NAME).
* @return string
*/
public static function alias($alias, $column)
{
return str_replace(ProductOptionsValueI18nPeer::TABLE_NAME.'.', $alias.'.', $column);
}
/**
* Add all the columns needed to create a new object.
*
* Note: any columns that were marked with lazyLoad="true" in the
* XML schema will not be added to the select list and only loaded
* on demand.
*
* @param criteria object containing the columns to add.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function addSelectColumns(Criteria $criteria)
{
$criteria->addSelectColumn(ProductOptionsValueI18nPeer::ID);
$criteria->addSelectColumn(ProductOptionsValueI18nPeer::CULTURE);
$criteria->addSelectColumn(ProductOptionsValueI18nPeer::VALUE);
if (stEventDispatcher::getInstance()->getListeners('ProductOptionsValueI18nPeer.postAddSelectColumns')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'ProductOptionsValueI18nPeer.postAddSelectColumns'));
}
}
const COUNT = 'COUNT(st_product_options_value_i18n.ID)';
const COUNT_DISTINCT = 'COUNT(DISTINCT st_product_options_value_i18n.ID)';
/**
* Returns the number of rows matching criteria.
*
* @param Criteria $criteria
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCount(Criteria $criteria, $distinct = false, $con = null)
{
// we're going to modify criteria, so copy it first
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsValueI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsValueI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$rs = ProductOptionsValueI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Method to select one object from the DB.
*
* @param Criteria $criteria object used to create the SELECT statement.
* @param Connection $con
* @return ProductOptionsValueI18n
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectOne(Criteria $criteria, $con = null)
{
$critcopy = clone $criteria;
$critcopy->setLimit(1);
$objects = ProductOptionsValueI18nPeer::doSelect($critcopy, $con);
if ($objects) {
return $objects[0];
}
return null;
}
/**
* Method to do selects.
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con
* @return ProductOptionsValueI18n[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelect(Criteria $criteria, $con = null)
{
return ProductOptionsValueI18nPeer::populateObjects(ProductOptionsValueI18nPeer::doSelectRS($criteria, $con));
}
/**
* Prepares the Criteria object and uses the parent doSelect()
* method to get a ResultSet.
*
* Use this method directly if you want to just get the resultset
* (instead of an array of objects).
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param Connection $con the connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return ResultSet The resultset object with numerically-indexed fields.
* @see BasePeer::doSelect()
*/
public static function doSelectRS(Criteria $criteria, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if (!$criteria->getSelectColumns()) {
$criteria = clone $criteria;
ProductOptionsValueI18nPeer::addSelectColumns($criteria);
}
if (stEventDispatcher::getInstance()->getListeners('BasePeer.preDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'BasePeer.preDoSelectRs'));
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
// BasePeer returns a Creole ResultSet, set to return
// rows indexed numerically.
$rs = BasePeer::doSelect($criteria, $con);
if (stEventDispatcher::getInstance()->getListeners('BasePeer.postDoSelectRs')) {
stEventDispatcher::getInstance()->notify(new sfEvent($rs, 'BasePeer.postDoSelectRs'));
}
return $rs;
}
/**
* The returned array will contain objects of the default type or
* objects that inherit from the default.
*
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function populateObjects(ResultSet $rs)
{
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
// set the class once to avoid overhead in the loop
$cls = ProductOptionsValueI18nPeer::getOMClass();
$cls = Propel::import($cls);
// populate the object(s)
while($rs->next()) {
$obj = new $cls();
$obj->hydrate($rs);
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj) : $obj;
}
return $results;
}
/**
* Returns the number of rows matching criteria, joining the related ProductOptionsValue table
*
* @param Criteria $c
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCountJoinProductOptionsValue(Criteria $criteria, $distinct = false, $con = null)
{
// we're going to modify criteria, so copy it first
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsValueI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsValueI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$criteria->addJoin(ProductOptionsValueI18nPeer::ID, ProductOptionsValuePeer::ID);
$rs = ProductOptionsValueI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Selects a collection of ProductOptionsValueI18n objects pre-filled with their ProductOptionsValue objects.
*
* @return ProductOptionsValueI18n[] Array of ProductOptionsValueI18n objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinProductOptionsValue(Criteria $c, $con = null)
{
$c = clone $c;
// Set the correct dbName if it has not been overridden
if ($c->getDbName() == Propel::getDefaultDB()) {
$c->setDbName(self::DATABASE_NAME);
}
ProductOptionsValueI18nPeer::addSelectColumns($c);
ProductOptionsValuePeer::addSelectColumns($c);
$c->addJoin(ProductOptionsValueI18nPeer::ID, ProductOptionsValuePeer::ID);
$rs = ProductOptionsValueI18nPeer::doSelectRs($c, $con);
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
while($rs->next()) {
$obj1 = new ProductOptionsValueI18n();
$startcol = $obj1->hydrate($rs);
if ($obj1->getId())
{
$obj2 = new ProductOptionsValue();
$obj2->hydrate($rs, $startcol);
$obj2->addProductOptionsValueI18n($obj1);
}
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj1) : $obj1;;
}
return $results;
}
/**
* Returns the number of rows matching criteria, joining all related tables
*
* @param Criteria $c
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
* @param Connection $con
* @return int Number of matching rows.
*/
public static function doCountJoinAll(Criteria $criteria, $distinct = false, $con = null)
{
$criteria = clone $criteria;
// clear out anything that might confuse the ORDER BY clause
$criteria->clearSelectColumns()->clearOrderByColumns();
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
$criteria->addSelectColumn(ProductOptionsValueI18nPeer::COUNT_DISTINCT);
} else {
$criteria->addSelectColumn(ProductOptionsValueI18nPeer::COUNT);
}
// just in case we're grouping: add those columns to the select statement
foreach($criteria->getGroupByColumns() as $column)
{
$criteria->addSelectColumn($column);
}
$criteria->addJoin(ProductOptionsValueI18nPeer::ID, ProductOptionsValuePeer::ID);
$rs = ProductOptionsValueI18nPeer::doSelectRS($criteria, $con);
if ($rs->next()) {
return $rs->getInt(1);
} else {
// no rows returned; we infer that means 0 matches.
return 0;
}
}
/**
* Selects a collection of ProductOptionsValueI18n objects pre-filled with all related objects.
*
* @return ProductOptionsValueI18n[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinAll(Criteria $c, $con = null)
{
$c = clone $c;
// Set the correct dbName if it has not been overridden
if ($c->getDbName() == Propel::getDefaultDB()) {
$c->setDbName(self::DATABASE_NAME);
}
ProductOptionsValueI18nPeer::addSelectColumns($c);
$startcol2 = (ProductOptionsValueI18nPeer::NUM_COLUMNS - ProductOptionsValueI18nPeer::NUM_LAZY_LOAD_COLUMNS) + 1;
ProductOptionsValuePeer::addSelectColumns($c);
$startcol3 = $startcol2 + ProductOptionsValuePeer::NUM_COLUMNS;
$c->addJoin(ProductOptionsValueI18nPeer::ID, ProductOptionsValuePeer::ID);
$rs = BasePeer::doSelect($c, $con);
if (self::$hydrateMethod)
{
return call_user_func(self::$hydrateMethod, $rs);
}
$results = array();
while($rs->next()) {
$omClass = ProductOptionsValueI18nPeer::getOMClass();
$cls = Propel::import($omClass);
$obj1 = new $cls();
$obj1->hydrate($rs);
// Add objects for joined ProductOptionsValue rows
$omClass = ProductOptionsValuePeer::getOMClass();
$cls = Propel::import($omClass);
$obj2 = new $cls();
$obj2->hydrate($rs, $startcol2);
$newObject = true;
for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
$temp_obj1 = $results[$j];
$temp_obj2 = $temp_obj1->getProductOptionsValue(); // CHECKME
if (null !== $temp_obj2 && $temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
$newObject = false;
$temp_obj2->addProductOptionsValueI18n($obj1); // CHECKME
break;
}
}
if ($newObject) {
$obj2->initProductOptionsValueI18ns();
$obj2->addProductOptionsValueI18n($obj1);
}
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj1) : $obj1;
}
return $results;
}
/**
* Returns the TableMap related to this peer.
* This method is not needed for general use but a specific application could have a need.
* @return TableMap
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getTableMap()
{
return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
}
/**
* The class that the Peer will make instances of.
*
* This uses a dot-path notation which is tranalted into a path
* relative to a location on the PHP include_path.
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
*
* @return string path.to.ClassName
*/
public static function getOMClass()
{
return ProductOptionsValueI18nPeer::CLASS_DEFAULT;
}
/**
* Method perform an INSERT on the database, given a ProductOptionsValueI18n or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsValueI18n object containing data that is used to create the INSERT statement.
* @param Connection $con the connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsValueI18nPeer:doInsert:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsValueI18nPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} else {
$criteria = $values->buildCriteria(); // build Criteria from ProductOptionsValueI18n object
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->begin();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch(PropelException $e) {
$con->rollback();
throw $e;
}
foreach (sfMixer::getCallables('BaseProductOptionsValueI18nPeer:doInsert:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsValueI18nPeer', $values, $con, $pk);
}
return $pk;
}
/**
* Method perform an UPDATE on the database, given a ProductOptionsValueI18n or Criteria object.
*
* @param mixed $values Criteria or ProductOptionsValueI18n object containing data that is used to create the UPDATE statement.
* @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
* @return int The number of affected rows (if supported by underlying database driver).
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doUpdate($values, $con = null)
{
foreach (sfMixer::getCallables('BaseProductOptionsValueI18nPeer:doUpdate:pre') as $callable)
{
$ret = call_user_func($callable, 'BaseProductOptionsValueI18nPeer', $values, $con);
if (false !== $ret)
{
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$selectCriteria = new Criteria(self::DATABASE_NAME);
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
$comparison = $criteria->getComparison(ProductOptionsValueI18nPeer::ID);
$selectCriteria->add(ProductOptionsValueI18nPeer::ID, $criteria->remove(ProductOptionsValueI18nPeer::ID), $comparison);
$comparison = $criteria->getComparison(ProductOptionsValueI18nPeer::CULTURE);
$selectCriteria->add(ProductOptionsValueI18nPeer::CULTURE, $criteria->remove(ProductOptionsValueI18nPeer::CULTURE), $comparison);
} else { // $values is ProductOptionsValueI18n object
$criteria = $values->buildCriteria(); // gets full criteria
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
}
// set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
foreach (sfMixer::getCallables('BaseProductOptionsValueI18nPeer:doUpdate:post') as $callable)
{
call_user_func($callable, 'BaseProductOptionsValueI18nPeer', $values, $con, $ret);
}
return $ret;
}
/**
* Method to DELETE all rows from the st_product_options_value_i18n table.
*
* @return int The number of affected rows (if supported by underlying database driver).
*/
public static function doDeleteAll($con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += BasePeer::doDeleteAll(ProductOptionsValueI18nPeer::TABLE_NAME, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Method perform a DELETE on the database, given a ProductOptionsValueI18n or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ProductOptionsValueI18n object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param Connection $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doDelete($values, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(ProductOptionsValueI18nPeer::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity
} elseif ($values instanceof ProductOptionsValueI18n) {
$criteria = $values->buildPkeyCriteria();
} else {
// it must be the primary key
$criteria = new Criteria(self::DATABASE_NAME);
// primary key is composite; we therefore, expect
// the primary key passed to be an array of pkey
// values
if(count($values) == count($values, COUNT_RECURSIVE))
{
// array is not multi-dimensional
$values = array($values);
}
$vals = array();
foreach($values as $value)
{
$vals[0][] = $value[0];
$vals[1][] = $value[1];
}
$criteria->add(ProductOptionsValueI18nPeer::ID, $vals[0], Criteria::IN);
$criteria->add(ProductOptionsValueI18nPeer::CULTURE, $vals[1], Criteria::IN);
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->begin();
$affectedRows += BasePeer::doDelete($criteria, $con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Validates all modified columns of given ProductOptionsValueI18n object.
* If parameter $columns is either a single column name or an array of column names
* than only those columns are validated.
*
* NOTICE: This does not apply to primary or foreign keys for now.
*
* @param ProductOptionsValueI18n $obj The object to validate.
* @param mixed $cols Column name or array of column names.
*
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
*/
public static function doValidate(ProductOptionsValueI18n $obj, $cols = null)
{
$columns = array();
if ($cols) {
$dbMap = Propel::getDatabaseMap(ProductOptionsValueI18nPeer::DATABASE_NAME);
$tableMap = $dbMap->getTable(ProductOptionsValueI18nPeer::TABLE_NAME);
if (! is_array($cols)) {
$cols = array($cols);
}
foreach($cols as $colName) {
if ($tableMap->containsColumn($colName)) {
$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
$columns[$colName] = $obj->$get();
}
}
} else {
}
$res = BasePeer::doValidate(ProductOptionsValueI18nPeer::DATABASE_NAME, ProductOptionsValueI18nPeer::TABLE_NAME, $columns);
if ($res !== true) {
$request = sfContext::getInstance()->getRequest();
foreach ($res as $failed) {
$col = ProductOptionsValueI18nPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
$request->setError($col, $failed->getMessage());
}
}
return $res;
}
/**
* Retrieve object using using composite pkey values.
* @param int $id
@param string $culture
* @param Connection $con
* @return ProductOptionsValueI18n
*/
public static function retrieveByPK( $id, $culture, $con = null) {
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$criteria = new Criteria();
$criteria->add(ProductOptionsValueI18nPeer::ID, $id);
$criteria->add(ProductOptionsValueI18nPeer::CULTURE, $culture);
$v = ProductOptionsValueI18nPeer::doSelect($criteria, $con);
return !empty($v) ? $v[0] : null;
}
} // BaseProductOptionsValueI18nPeer
// static code to register the map builder for this Peer with the main Propel class
if (Propel::isInit()) {
// the MapBuilder classes register themselves with Propel during initialization
// so we need to load them here.
try {
BaseProductOptionsValueI18nPeer::getMapBuilder();
} catch (Exception $e) {
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
}
} else {
// even if Propel is not yet initialized, the map builder class can be registered
// now and then it will be loaded when Propel initializes.
Propel::registerMapBuilder('plugins.stProductOptionsPlugin.lib.model.map.ProductOptionsValueI18nMapBuilder');
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,150 @@
<?php
class stFixProductOptions {
public function fix($step) {
$c = new Criteria();
$c->setOffset($step);
$c->addAscendingOrderByColumn(ProductPeer::ID);
$product = ProductPeer::doSelectOne($c);
$c = new Criteria();
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product->getId());
$values = ProductOptionsValuePeer::doSelect($c);
foreach ($values as $value) {
$this->deleteOld($value);
}
$values = ProductOptionsValuePeer::doSelect($c);
foreach ($values as $value) {
$this->repair($value);
}
$values = ProductOptionsValuePeer::doSelect($c);
foreach ($values as $value) {
$value->save();
$this->fixDepth($value);
$this->fixTemplateId($value);
}
foreach ($values as $value) {
$value = $value->reload();
$this->fixField($value);
}
foreach ($values as $value) {
$value = $value->reload();
$this->fixStock($value);
$value->save();
}
return ($step+1);
}
public function fixDepth($object) {
if ($object->getDepth()==null) {
$c = new Criteria();
$c->add(ProductOptionsValuePeer::LFT,$object->getLft(), Criteria::LESS_THAN);
$c->add(ProductOptionsValuePeer::RGT,$object->getRgt(), Criteria::GREATER_THAN);
$c->add(ProductOptionsValuePeer::PRODUCT_ID,$object->getProductId());
$object->setDepth(ProductOptionsValuePeer::doCount($c));
}
}
public function fixStock($object) {
if (!$object->isLeaf()) {
$con = Propel::getConnection();
$stmt = $con->createStatement();
$sql = "SELECT SUM(".ProductOptionsValuePeer::STOCK.") as option_stock FROM ".ProductOptionsValuePeer::TABLE_NAME."
WHERE ".ProductOptionsValuePeer::LFT.">".$object->getLft()." AND ".ProductOptionsValuePeer::RGT."<".$object->getRgt()."
AND ".ProductOptionsValuePeer::PRODUCT_ID."=".$object->getProductId();
$rs = $stmt->executeQuery($sql);
if ($rs->next()) {
$object->setStock((int)$rs->getInt('option_stock'));
}
}
}
public function fixField($object) {
if (!$object->isRoot()) {
$field_id = $object->getProductOptionsFieldId();
$field = $object->getProductOptionsField();
if (is_object($field)) {
if (is_object($object->getParent())) {
if ($field->getOptValueId() != $object->getParent()->getId()) {
print $field->getOptValueId()."->".$object->getParent()->getId()."<br />";
$newField = new ProductOptionsField();
$newField->setCulture('pl_PL');
$newField->setName($field->getName());
$newField->setProductOptionsTemplateId(0);
$newField->setOptDefaultValue($field->getOptDefaultValue());
$newField->setOptValueId($object->getParent()->getId());
$newField->save();
$c = new Criteria();
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID, $field_id);
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $object->getProductId());
foreach (ProductOptionsValuePeer::doSelect($c) as $value) {
$value->setProductOptionsFieldId($newField->getId());
$value->save();
}
}
}
} else {
}
}
}
public function fixDeletedTemplate($object) {
if ($object->getDepth()==1 && !is_object($object->getParent())) {
$c = new Criteria();
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $object->getProductId());
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_VALUE_ID, null, Criteria::ISNULL);
$parent = ProductOptionsValuePeer::doSelectOne($c);
$object->insertAsLastChildOf($parent);
}
}
public function fixTemplateId($object) {
if (!$object->isRoot()) {
$object->setProductOptionsTemplateId(0);
}
}
public function fixStockForField($object) {
if (!$object->isRoot()) {
}
}
public function deleteOld($object) {
if ($object->getProductOptionsValueId()!=null && !is_object($object->getParent())) {
$object->delete();
}
}
public function repair($parent) {
$c = new Criteria();
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $parent->getProductId());
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_VALUE_ID, $parent->getId());
$c->addAscendingOrderByColumn(ProductOptionsValuePeer::ID);
$options = ProductOptionsValuePeer::doSelect($c);
foreach ($options as $option) {
$parent = $parent->reload();
$option->insertAsLastChildOf($parent);
$option->save();
}
}
public static function count() {
return ProductPeer::doCount(new Criteria());
}
}

View File

@@ -0,0 +1,949 @@
<?php
/**
* Optimized version of product options managment
*/
class stNewProductOptions
{
protected static $cachePool = array();
protected static $filtersPool = null;
protected static $post_product_criteria = null;
protected static $pre_product_criteria = null;
protected static $hide_no_stock = true;
public static function updateProduct(Product $product, $selected_ids = array(), $selected_values = array(), $hide_no_stock = true)
{
$debug = sfConfig::get('sf_logging_enabled') && sfConfig::get('sf_debug');
if ($debug)
{
$timer = sfTimerManager::getTimer('__SOTE stNewProductOptions::updateProduct()');
}
if (!isset(self::$cachePool[$product->getId()]))
{
$options = ProductOptionsValuePeer::doSelectByProduct($product, $hide_no_stock);
$price_type = ProductOptionsValuePeer::getPriceType($product);
self::$hide_no_stock = $hide_no_stock;
self::updateProductRecursive($product, $options, $price_type, $selected_ids, $asset_image_id, $selected_values);
self::updateProductImage($product, $asset_image_id);
stEventDispatcher::getInstance()->notify(new sfEvent($product, 'stNewProductOptions.updateProduct'));
self::$cachePool[$product->getId()] = array(
'price_modifiers' => $product->getPriceModifiers(),
'stock' => $product->getStock(),
'weight' => $product->getWeight(),
'selected_options' => $selected_ids,
'asset_image' => $product->getDefaultAssetImage(),
'image' => $product->getOptImage(),
'currency_old_price' => $product->getCurrencyOldPrice(),
'old_price' => $product->getOldPriceBrutto(),
'code' => $product->getCode(),
'man_code' => $product->getManCode(),
'pum' => $product->getBpumDefaultValue(),
);
self::$hide_no_stock = true;
}
else
{
$cache = self::$cachePool[$product->getId()];
$product->setPriceModifiers($cache['price_modifiers']);
$product->setStock($cache['stock']);
$product->setWeight($cache['weight']);
$product->setBpumDefaultValue($cache['pum']);
$product->setDefaultAssetImage($cache['asset_image']);
$product->setOptImage($cache['image']);
$product->setOldPriceBrutto($cache['old_price']);
$product->setCurrencyOldPrice($cache['currency_old_price']);
$product->setCode($cache['code']);
$product->setManCode($cache['man_code']);
$selected_ids = $cache['selected_options'];
$product->resetModified();
}
if ($debug)
{
$timer->addTime();
}
return $selected_ids;
}
public static function getSelectedOptions($product)
{
return isset(self::$cachePool[$product->getId()]) ? self::$cachePool[$product->getId()]['selected_options'] : array();
}
/**
*
* @param Product $product
* @param ProductOptionsValue[] $options
* @param array $allowedParentIds
* @param array $reserverFieldIds
* @return bool Zwraca false w przypadku niedozwolonej kombinacji opcji produktu
* @throws PropelException
* @throws SQLException
*/
public static function updateProductBySelectedOptions(Product $product, array $options, array &$allowedParentIds = [], array &$reserverFieldIds = [])
{
if ($options)
{
ProductOptionsValue::setProductPool($product);
$price_type = ProductOptionsValuePeer::getPriceType($product);
$image = null;
$product->setPriceModifiers(array());
foreach ($options as $option)
{
if (!empty($allowedParentIds) && !isset($allowedParentIds[$option->getProductOptionsValueId()]) || isset($reserverFieldIds[$option->getProductOptionsFieldId()]))
{
return false;
}
if (isset($allowedParentIds[$option->getId()]))
{
continue;
}
self::addProductPriceModifier($product, $option->getPrice($price_type), $option->getDepth(), $price_type, array('id' => $option->getId(), 'label' => $option->getValue(), 'color' => $option->getUseImageAsColor() ? $option->getColorImagePath() : $option->getColor(), 'field' => $option->getProductOptionsField()->getName(), 'type' => 'product_options'));
if ($option->getsfAssetId())
{
$image = $option->getsfAssetId();
}
if ($option->isLeaf())
{
self::updateProductStock($product, $option->getStock());
}
self::updateProductOldPrice($product, $option);
self::updateProductWeight($product, $option->getWeight());
if ($option->getUseProduct())
{
$product->setCode($option->getUseProduct());
}
if ($option->getManCode())
{
$product->setManCode($option->getManCode());
}
if ($option->getPum())
{
$product->setBpumDefaultValue($option->getPum());
}
$allowedParentIds[$option->getId()] = $option->getId();
$allowedParentIds[$option->getProductOptionsValueId()] = $option->getProductOptionsValueId();
$reserverFieldIds[$option->getProductOptionsFieldId()] = $option->getProductOptionsFieldId();
}
self::updateProductImage($product, $image);
$product->resetModified();
}
return true;
}
/**
*
* @param Product $product
* @param ProductOptionsValue[] $options
* @param string $price_type
* @param int[] $selected_ids
* @param int $asset_image_id
* @param array $selected_values
* @param int $index
* @return void
* @throws PropelException
* @throws SQLException
*/
public static function updateProductRecursive($product, $options, $price_type, &$selected_ids, &$asset_image_id, &$selected_values = array(), &$index = 0)
{
if (empty($options))
{
if ($product->hasOptions())
{
self::updateProductStock($product, 0);
}
return;
}
$selectDefaultOptions = !$product->getConfiguration()->get('disable_default_option_select', false);
$selected = null;
$field_id = $options[0]->getProductOptionsFieldId();
$first_option = $options[0];
foreach ($options as $option)
{
$field = $option->getProductOptionsField();
if ($selectDefaultOptions && null === $selected && $option->getOptValue() == $field->getOptDefaultValue() && $field->getId() == $field_id)
{
$selected = $option;
}
if (isset($selected_values[$index]) && isset($selected_values[$index][trim($option->getOptValue())]))
{
$selected = $option;
unset($selected_values[$index][trim($option->getOptValue())]);
}
if ($field->getId() != $field_id && ($selectDefaultOptions || null !== $selected))
{
self::updateProductRecursiveHelper($product, $price_type, $selected_ids, $asset_image_id, $selected_values, $index, $option, $selected, $field_id, $first_option);
}
}
if ($selectDefaultOptions || null !== $selected)
{
self::updateProductRecursiveHelper($product, $price_type, $selected_ids, $asset_image_id, $selected_values, $index, $option, $selected, $field_id, $first_option);
}
$product->resetModified();
}
/**
*
* @param Product $product
* @param mixed $price_type
* @param mixed $selected_ids
* @param mixed $asset_image_id
* @param array $selected_values
* @param int $index
* @param mixed $option
* @param mixed $selected
* @param mixed $field_id
* @param mixed $first_option
* @return void
* @throws PropelException
* @throws SQLException
*/
public static function updateProductRecursiveHelper($product, $price_type, &$selected_ids, &$asset_image_id, &$selected_values = array(), &$index = 0, $option, &$selected, &$field_id, &$first_option)
{
$index++;
$field = $option->getProductOptionsField();
if (null === $selected)
{
$selected = $first_option;
}
$selected_ids[$field_id] = $selected->getId();
if ($selected->getsfAssetId())
{
$asset_image_id = $selected->getsfAssetId();
}
self::addProductPriceModifier($product, $selected->getPrice($price_type), $selected->getDepth(), $price_type, array('id' => $selected->getId(), 'label' => $selected->getValue(), 'color' => $selected->getUseImageAsColor() ? $selected->getColorImagePath() : $selected->getColor(), 'field' => $selected->getProductOptionsField()->getName(), 'type' => 'product_options'));
self::updateProductWeight($product, $selected->getWeight());
if ($selected->getUseProduct())
{
$product->setCode($selected->getUseProduct());
}
if ($selected->getManCode())
{
$product->setManCode($selected->getManCode());
}
if ($selected->hasChildren())
{
self::updateProductOldPrice($product, $selected);
self::updateProductRecursive($product, $selected->getChildOptions($product->getConfiguration()->get('hide_options_with_empty_stock') && self::$hide_no_stock), $price_type, $selected_ids, $asset_image_id, $selected_values, $index);
}
else
{
self::updateProductStock($product, $selected->getStock());
self::updateProductOldPrice($product, $selected);
if ($selected->getPum())
{
$product->setBpumDefaultValue($selected->getPum());
}
}
$selected = null;
$first_option = $option;
if (isset($selected_values[$index]) && isset($selected_values[$index][trim($option->getOptValue())]))
{
$selected = $option;
unset($selected_values[$index][trim($option->getOptValue())]);
}
$field_id = $field->getId();
}
/**
* Zwraca wybrane opcje w postaci nazwa i przypisanymi ich ID
*
* @param ProductOptionsValue $option
* @param array $selected Wybrane opcje
* @param array $values Wybrane nazwy wartości opcji i odpowiadające im ID
* @param array $parents Zmienna pomocnicza
* @param mixed $index Zmienna pomocnicza
* @return void
*/
public static function buildSelectOptionsValues(ProductOptionsValue $option, array $selected, array &$values, array &$parents = [], &$index = 0)
{
if ($index > 0 && $option->getDepth() > 1 && !isset($parents[$option->getParentId()]))
{
return;
}
$selectDefaultOptions = stConfig::getInstance('stProduct')->get('disable_default_option_select', false);
$values[$index][trim($option->getOptValue())] = $option->getId();
$parents[$option->getId()] = $option->getId();
$index++;
if ($option->hasChildren())
{
foreach ($option->getChildren() as $child)
{
$field = $child->getProductOptionsField();
$isSelected = isset($selected[$field->getId()]) ? $selected[$field->getId()] : null;
if (!in_array($child->getId(), $selected) && (null === $isSelected && $selectDefaultOptions && $field->getOptDefaultValue() == $child->getOptValue() || null !== $isSelected && $isSelected == $child->getId()))
{
self::buildSelectOptionsValues($child, $selected, $values, $parents, $index);
}
}
}
}
public static function updateProductWeight($product, $weight)
{
list($prefix, $type, $value) = self::parseValue($weight);
$base_weight = $product->getWeight();
if ($type == 'percent')
{
$value = stPrice::percentValue($base_weight, $value);
}
if ($prefix)
{
$base_weight += $prefix . $value;
}
elseif ($value != 0)
{
$base_weight = $value;
}
if ($base_weight < 0)
{
$base_weight = 0;
}
$product->setWeight(stPrice::round($base_weight));
}
public static function parseValue($value)
{
if (!$value)
{
return array(null, 'numeric', null);
}
$prefix = $value{
0} == '+' || $value{
0} == '-' ? $value{
0} : null;
$type = substr($value, -1) == '%' ? 'percent' : 'numeric';
return array($prefix, $type, floatval(trim($value, '+-%')));
}
/**
* Dodaje modyfikator ceny do produktu
*
* @param Product $product
* @param string $price Modyfikator ceny
* @param int $depth Poziom
* @param string $price_type Typ ceny
* @param array $custom Własne parametry
* @return void
*/
public static function addProductPriceModifier($product, $price, $depth, $price_type, $custom = array())
{
if (!$price)
{
$value = null;
$type = null;
$prefix = null;
}
else
{
list($prefix, $type, $price_value) = self::parseValue($price);
if ($type == 'numeric')
{
$price = $price_value;
$tax = $product->getTax();
$taxRate = $product->getVat();
$type = 'numeric';
if ($product->getCurrencyExchange() != 1)
{
$value = array('currency_brutto' => $price, 'tax' => $taxRate);
$value['brutto'] = stCurrency::calculateCurrencyPrice($price, $product->getCurrencyExchange(), true);
$value['netto'] = stPrice::extract($value['brutto'], $taxRate);
$value['currency_netto'] = stCurrency::calculateCurrencyPrice($value['netto'], $product->getCurrencyExchange());
}
else
{
$value = array($price_type => $price, 'tax' => $taxRate);
if ($price_type == 'netto')
{
$value['brutto'] = stPrice::calculate($price, $taxRate);
}
else
{
if ($tax && null !== $tax->getTaxRateByCountry())
{
$value['netto'] = stPrice::extract($price, $tax->getDefaultTaxRate());
$value['brutto'] = stPrice::calculate($value['netto'], $tax->getTaxRateByCountry());
}
else
{
$value['netto'] = stPrice::extract($price, $taxRate);
}
}
}
}
else
{
$value = $price_value;
}
}
$product->addPriceModifier($value, $type, $prefix, $depth, $custom);
}
public static function updateProductStock($product, $stock)
{
if ($product->getStockManagment() == ProductPeer::STOCK_PRODUCT_OPTIONS && $product->getStock() !== null && null !== $stock)
{
$product->setStock($stock);
}
}
public static function updateProductOldPrice($product, $selected)
{
$oldPrice = $selected->getOldPrice();
if ($oldPrice > 0)
{
if ($product->getCurrencyExchange() != 1)
{
$product->setCurrencyOldPrice($oldPrice);
$product->setOldPriceBrutto($product->getGlobalCurrency()->exchange($oldPrice, true, $product->getCurrencyExchange()));
}
else
{
if (ProductOptionsValuePeer::getPriceType($product) == 'netto')
{
$product->setOldPriceBrutto(stPrice::calculate($oldPrice, $product->getOptVat()));
}
else
{
$product->setOldPriceBrutto($oldPrice);
}
}
}
}
public static function updateProductImage($product, $asset)
{
if ($asset)
{
$product->setDefaultAssetImage($asset);
$default = $product->getDefaultAssetImage();
if ($default)
{
$product->setOptImage($default->getRelativePath());
}
}
}
/**
* Kopiowanie opcji produktu
* @param object $source element zrodlowy
* @param object $dest element docelowy
*/
static public function copyDescendands($source, $dest)
{
if (count($source->getChildren()) != 0)
{
$transform_fields = array();
foreach ($source->getChildren() as $srcValue)
{
$dest = $dest->reload();
$newChild = new ProductOptionsValue();
$newChild->setProductId($dest->getProductId());
$newChild->setProductOptionsTemplateId(0);
$newChild->setCulture($srcValue->getCulture());
$newChild->setValue($srcValue->getValue());
$newChild->setStock($srcValue->getStock());
$newChild->setPrice($srcValue->getPrice());
$newChild->setPriceType($srcValue->getPriceType());
$newChild->setSfAsset(self::getDuplicatedImageId($dest->getProductId(), $srcValue));
$newChild->insertAsLastChildOf($dest);
$newChild->save();
if (empty($transform_fields[$srcValue->getProductOptionsFieldId()]))
{
$newField = new ProductOptionsField();
$oldField = $srcValue->getProductOptionsField();
$newField->setRequired($oldField->getRequired());
$newField->setProductOptionsTemplateId(0);
$newField->setCulture($oldField->getCulture());
$newField->setName($oldField->getName());
$newField->setDefaultValue($newField->getDefaultValue());
$newField->setOptValueId($newChild->getParentId());
$newField->save();
foreach ($oldField->getProductOptionsFieldI18ns() as $i18n)
{
$newField->setCulture($i18n->getCulture());
$newField->setName($i18n->getName());
$newField->setDefaultValue($i18n->getDefaultValue());
$newField->save();
}
$transform_fields[$srcValue->getProductOptionsFieldId()] = $newField->getId();
}
$newChild->setProductOptionsFieldId($transform_fields[$srcValue->getProductOptionsFieldId()]);
$newChild->save();
foreach ($srcValue->getProductOptionsValueI18ns() as $sourceI18n)
{
$newChild->setCulture($sourceI18n->getCulture());
$newChild->setValue($sourceI18n->getValue());
$newChild->setId($newChild->getId());
$newChild->save();
}
self::copyDescendands($srcValue, $newChild);
}
}
}
public static function getDuplicatedImageId($dest_product_id, $src_option)
{
$src_asset = $src_option->getSfAsset();
if (is_object($src_asset))
{
$src_filename = $src_asset->getFilename();
$c = new Criteria();
$c->add(ProductHasSfAssetPeer::PRODUCT_ID, $dest_product_id);
$c->add(SfAssetPeer::FILENAME, $src_filename);
$c->addJoin(SfAssetPeer::ID, ProductHasSfAssetPeer::SF_ASSET_ID);
return SfAssetPeer::doSelectOne($c);
}
return null;
}
public static function clearCache($product = null)
{
$product->setPriceModifiers(array());
if (isset(self::$cachePool[$product->getId()]))
{
unset(self::$cachePool[$product->getId()]);
}
}
public static function clearStaticPool()
{
ProductOptionsValuePeer::clearStatic();
self::$cachePool = array();
}
public static function getOptionsFilters()
{
$pConfig = stConfig::getInstance(null, 'stProduct');
$c = new Criteria();
$c->add(ProductOptionsFilterPeer::FILTER_TYPE, ProductOptionsFilterPeer::PRICE_FILTER, Criteria::NOT_EQUAL);
$c->add(ProductOptionsFilterPeer::IS_VISIBLE, true);
$filters = ProductOptionsFilterPeer::doSelectWithI18n($c);
if (!$filters)
{
return array();
}
$ids = array();
foreach ($filters as $filter)
{
$ids[] = $filter->getId();
}
/**
* @var Criteria
*/
$c = !stConfig::getInstance('stProduct')->get('filter_narrow') ? clone self::$post_product_criteria : clone self::$pre_product_criteria;
$c->clearOrderByColumns();
$c->clearGroupByColumns();
$c->clearSelectColumns();
if ($pConfig->get('hide_options_with_empty_stock'))
{
$c->add(ProductOptionsValuePeer::STOCK, sprintf('(%1$s IS NULL OR %1$s > 0)', ProductOptionsValuePeer::STOCK), Criteria::CUSTOM);
}
$c->addSelectColumn(ProductOptionsValuePeer::OPT_FILTER_ID);
$c->add(ProductOptionsValuePeer::IS_ACTIVE, true);
$c->add(ProductOptionsValuePeer::OPT_FILTER_ID, $ids, Criteria::IN);
$c->addJoin(ProductPeer::ID, ProductOptionsValuePeer::PRODUCT_ID);
$c->addGroupByColumn(ProductOptionsValuePeer::OPT_FILTER_ID);
$c->addGroupByColumn(ProductPeer::ID);
$c->setDistinct();
$rs = ProductOptionsValuePeer::doSelectRS($c);
$available_ids = array();
while ($rs->next())
{
$row = $rs->getRow();
$available_ids[$row[0]] = $row[0];
}
$results = array();
if ($available_ids)
{
foreach ($filters as $index => $filter)
{
if (isset($available_ids[$filter->getId()]))
{
$results[] = $filter;
}
}
}
return $results;
}
public static function getOptionsForFilter($filter)
{
$config = stConfig::getInstance(null, 'stProduct');
/**
* @var Criteria
*/
$c = !stConfig::getInstance('stProduct')->get('filter_narrow') ? clone self::$post_product_criteria : clone self::$pre_product_criteria;
$c->clearOrderByColumns();
$c->clearGroupByColumns();
$c->clearSelectColumns();
$c->setLimit(null);
$c->setOffset(null);
if ($filter->getFilterType() == 2)
{
$c->addSelectColumn(ProductOptionsValuePeer::COLOR);
}
else
{
$c->addSelectColumn(ProductOptionsValuePeer::OPT_VALUE);
}
$c->add(ProductOptionsValuePeer::OPT_FILTER_ID, $filter->getId());
$c->addJoin(ProductPeer::ID, ProductOptionsValuePeer::PRODUCT_ID);
if ($filter->getFilterType() == 2)
{
$c->addGroupByColumn(ProductOptionsValuePeer::COLOR);
}
else
{
$c->addGroupByColumn(ProductOptionsValuePeer::OPT_VALUE);
}
$c->addGroupByColumn(ProductPeer::ID);
$c->add(ProductOptionsValuePeer::IS_ACTIVE, true);
if ($config->get('hide_options_with_empty_stock'))
{
$c->add(ProductOptionsValuePeer::STOCK, sprintf('(%1$s IS NULL OR %1$s > 0)', ProductOptionsValuePeer::STOCK), Criteria::CUSTOM);
}
$c->setDistinct();
$rs = ProductOptionsValuePeer::doSelectRS($c);
$rs->setFetchmode(ResultSet::FETCHMODE_NUM);
$values = array();
while ($rs->next())
{
$values[] = $rs->getString(1);
}
$oc = new Criteria();
$oc->add(ProductOptionsValuePeer::OPT_FILTER_ID, $filter->getId());
if ($filter->getFilterType() == 2)
{
$oc->add(ProductOptionsValuePeer::COLOR, $values, Criteria::IN);
$oc->addGroupByColumn(ProductOptionsValuePeer::COLOR);
}
else
{
$oc->add(ProductOptionsValuePeer::OPT_VALUE, $values, Criteria::IN);
$oc->addGroupByColumn(ProductOptionsValuePeer::OPT_VALUE);
}
$options = ProductOptionsValuePeer::doSelectWithI18n($oc);
uasort($options, array('stNewProductOptions', 'sortHelper'));
return $options;
}
public static function sortHelper($o1, $o2)
{
return strnatcasecmp($o1->getValue(), $o2->getValue());
}
public static function sortHelperArray($o1, $o2)
{
return strnatcasecmp($o1['value'], $o2['value']);
}
/**
* Returns Filter criteria
*
* @return Criteria
*/
protected static function getCriteriaForFilter()
{
$c = !stConfig::getInstance('stProduct')->get('filter_narrow') ? clone self::$post_product_criteria : clone self::$pre_product_criteria;
$c->clearSelectColumns()->clearOrderByColumns();
$c->addSelectColumn(ProductPeer::ID);
$c->add('custom_option_join', sprintf("%s = %s", ProductOptionsValuePeer::PRODUCT_ID, ProductPeer::ID), Criteria::CUSTOM | Criteria::IGNORE_TABLE);
$c->setLimit(null);
$c->setOffset(null);
return $c;
}
protected static function getFilterById($id)
{
if (null === self::$filtersPool)
{
$filters = array();
foreach (ProductOptionsFilterPeer::doSelect(new Criteria()) as $filter)
{
$filters[$filter->getId()] = $filter;
}
self::$filtersPool = $filters;
}
return isset(self::$filtersPool[$id]) ? self::$filtersPool[$id] : null;
}
public static function listFilter($event)
{
$action = $event->getSubject();
if (isset($action->product_pager))
{
$request = $action->getRequest();
if (!$request->hasParameter('filter') && $request->getHttpHeader('X-Moz') != 'prefetch')
{
self::clearFilters($action->getContext());
}
$c = $action->product_pager->getCriteria();
self::addOptionsFilterCriteria($action->getContext(), $c);
}
}
public static function addOptionsFilterCriteria(sfContext $context, Criteria $c)
{
self::$pre_product_criteria = clone $c;
$config = stConfig::getInstance('stProduct');
if (stNewProductOptions::hasFilters($context))
{
$pConfig = stConfig::getInstance('stProduct');
$filters = stNewProductOptions::getFilters($context);
if ($filters)
{
foreach ($filters as $id => $selected)
{
$filter = self::getFilterById($id);
$oc = new Criteria();
$oc->addSelectColumn(ProductOptionsValuePeer::ID);
$oc->add(ProductOptionsValuePeer::PRODUCT_ID, sprintf("%s = %s", ProductOptionsValuePeer::PRODUCT_ID, ProductPeer::ID), Criteria::CUSTOM);
$oc->add(ProductOptionsValuePeer::IS_ACTIVE, true);
if ($pConfig->get('hide_options_with_empty_stock'))
{
$oc->add(ProductOptionsValuePeer::STOCK, sprintf('(%1$s IS NULL OR %1$s > 0)', ProductOptionsValuePeer::STOCK), Criteria::CUSTOM);
}
$oc->add($filter->getFilterType() == 2 ? ProductOptionsValuePeer::COLOR : ProductOptionsValuePeer::OPT_VALUE, array_values($selected), Criteria::IN);
$oc->add(ProductOptionsValuePeer::OPT_FILTER_ID, $id);
$query = BasePeer::createSqlQuery($oc);
$cnew = $c->getNewCriterion(ProductPeer::ID, sprintf("EXISTS (%s)", $query), Criteria::CUSTOM);
$c->addAnd($cnew);
}
}
}
self::$post_product_criteria = clone $c;
}
public static function getFilters(sfContext $context)
{
return $context->getUser()->getAttribute('filters', array(), stProductFilter::getNamespace($context, 'soteshop/stProductOptions'));
}
public static function hasFilters(sfContext $context)
{
return (bool)self::getFilters($context);
}
public static function setFilters(sfContext $context, $filters)
{
$context->getUser()->setAttribute('filters', $filters, stProductFilter::getNamespace($context, 'soteshop/stProductOptions'));
}
public static function clearFilters(sfContext $context, $filter = null)
{
$filters = self::getFilters($context);
if ($filter && isset($filters[$filter]))
{
unset($filters[$filter]);
}
elseif (null === $filter)
{
$filters = array();
}
self::setFilters($context, $filters);
}
public static function saveProductColors($event)
{
$product = $event->getSubject();
$product_id = $product->getId();
if (!$product->isNew())
{
$c = new Criteria();
$c->addSelectColumn(ProductOptionsFilterPeer::ID);
$c->add(ProductOptionsFilterPeer::FILTER_TYPE, 2);
$rs = ProductOptionsFilterPeer::doSelectRs($c);
$filters = array();
while ($rs->next())
{
$filters[] = $rs->getInt(1);
}
if ($filters)
{
$c = new Criteria();
$c->addSelectColumn(ProductOptionsValuePeer::ID);
$c->addSelectColumn(ProductOptionsValuePeer::COLOR);
$c->addSelectColumn(ProductOptionsValuePeer::STOCK);
$c->addSelectColumn(ProductOptionsValuePeer::USE_IMAGE_AS_COLOR);
$c->add(ProductOptionsValuePeer::LFT, ProductOptionsValuePeer::RGT . " - " . ProductOptionsValuePeer::LFT . " > 0", Criteria::CUSTOM);
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product_id);
$c->add(ProductOptionsValuePeer::OPT_FILTER_ID, $filters, Criteria::IN);
$c->addDescendingOrderByColumn(ProductOptionsValuePeer::STOCK);
$c->addGroupByColumn(ProductOptionsValuePeer::COLOR);
$rs = ProductOptionsValuePeer::doSelectRs($c);
$colors = array();
while ($rs->next())
{
$row = $rs->getRow();
$colors[] = array(
'color' => $row[3] ? ProductOptionsValuePeer::getColorImagePath($product_id, $row[0], $row[1]) : $row[1],
'stock' => $row[2],
'image_as_color' => $row[3]
);
}
$product->setOptionsColor($colors);
}
}
}
}

View File

@@ -0,0 +1,79 @@
<?php
class stProductOptionsFix
{
protected static $dbm = null;
public function executeUpdate($offset)
{
self::initDatabase();
$offset = self::execute($offset);
self::shutdownDatabase();
return $offset;
}
public function execute($offset)
{
$c = new Criteria();
$c->addSelectColumn(ProductPeer::ID);
$c->setLimit(50);
$c->setOffset($offset);
$rs = ProductPeer::doSelectRs($c);
$ids = array();
while($rs->next())
{
$id = $rs->getInt(1);
$ids[] = $id;
$ps = Propel::getConnection()->prepareStatement(sprintf('UPDATE %s, %s SET %s = %s WHERE %s = %s AND %s = ?',
ProductOptionsValuePeer::TABLE_NAME,
ProductOptionsFieldPeer::TABLE_NAME,
ProductOptionsValuePeer::OPT_FILTER_ID,
ProductOptionsFieldPeer::PRODUCT_OPTIONS_FILTER_ID,
ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID,
ProductOptionsFieldPeer::ID,
ProductOptionsValuePeer::PRODUCT_ID
));
$ps->setInt(1, $id);
$ps->executeUpdate();
ProductOptionsValuePeer::updateProductColor($id);
}
$con = Propel::getConnection();
$con->executeQuery(sprintf("UPDATE st_product_options_value v LEFT JOIN st_product_options_value c ON c.LFT BETWEEN v.LFT AND v.RGT AND c.product_id = v.product_id AND c.RGT - c.LFT = 1 AND c.stock > 0 SET v.stock = IFNULL(c.stock, 0) WHERE v.product_id IN (%s)",
implode(',', $ids)));
usleep(500000);
return $offset + count($ids);
}
public static function count()
{
return ProductPeer::doCount(new Criteria());
}
public static function initDatabase()
{
self::$dbm = new sfDatabaseManager();
self::$dbm->initialize();
}
public static function shutdownDatabase()
{
self::$dbm->shutdown();
}
}

View File

@@ -0,0 +1,844 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class stProductOptionsImportExport
{
public static $useLogger = true;
protected static $filterPool = array();
protected static $productOptionsColorPool = array();
protected static $valid = true;
protected static $jsonUnicode = false;
protected static $duplicates = array();
protected static $paramTranslation = array(
'filter' => 'filtr',
'default' => 'domyslna',
'price' => 'cena',
'old_price' => 'stara_cena',
'stock' => 'magazyn',
'weight' => 'waga',
'code' => 'kod',
'pum' => 'ijm',
'image' => 'zdjecie',
'option_color' => 'kolor_opcji',
'price_type' => 'typ_ceny',
'man_code' => 'kod_producenta',
);
protected static $paramsTranslation = null;
public static function getParamTranslation($name, $culture)
{
if ($culture == 'pl_PL' && isset(self::$paramTranslation[$name]))
{
return self::$paramTranslation[$name];
}
return $name;
}
public static function translateParams($params)
{
if (null === self::$paramsTranslation)
{
$from = array();
foreach (array_values(self::$paramTranslation) as $value)
{
$from[] = '"'.$value.'"';
}
$to = array();
foreach (array_keys(self::$paramTranslation) as $value)
{
$to[] = '"'.$value.'"';
}
self::$paramsTranslation = array(
'from' => $from,
'to' => $to,
);
}
return str_replace(self::$paramsTranslation['from'], self::$paramsTranslation['to'], $params);
}
/**
* Pobiera drzewo opcji dla produktu
* @param $product_id - id produktu
* @return object
*/
public static function getRootForProduct($product_id)
{
$c = new Criteria();
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID, null, Criteria::ISNULL);
$c->add(ProductOptionsValuePeer::PRODUCT_ID,$product_id);
$root = ProductOptionsValuePeer::doSelectOne($c);
if (!$root)
{
$root = new ProductOptionsValue();
$root->setProductId($product_id);
$root->makeRoot();
$root->_duplicated = true;
$root->save();
}
return $root;
}
/**
* Pobiera opcje danego produktu
* @param $object - obiekt produktu
* @return string
*/
public static function getProductOptions(Product $product)
{
/* PHP 5.3.x compatibility fix */
self::$jsonUnicode = defined('JSON_UNESCAPED_UNICODE');
$sf_context = sfContext::getInstance();
$culture = $sf_context->getUser()->getCulture();
$c = new Criteria();
$c->addSelectColumn(ProductOptionsValuePeer::ID);
$c->addSelectColumn(ProductOptionsFieldPeer::OPT_NAME);
$c->addSelectColumn(ProductOptionsFieldPeer::PRODUCT_OPTIONS_FILTER_ID);
$c->addSelectColumn(ProductOptionsFieldPeer::OPT_DEFAULT_VALUE);
$c->addSelectColumn(ProductOptionsValuePeer::SF_ASSET_ID);
$c->addSelectColumn(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID);
$c->addSelectColumn(ProductOptionsValuePeer::PRICE);
$c->addSelectColumn(ProductOptionsValuePeer::WEIGHT);
$c->addSelectColumn(ProductOptionsValuePeer::STOCK);
$c->addSelectColumn(ProductOptionsValuePeer::OPT_VALUE);
$c->addSelectColumn(ProductOptionsValuePeer::PRICE_TYPE);
$c->addSelectColumn(ProductOptionsValuePeer::COLOR);
$c->addSelectColumn(ProductOptionsValuePeer::USE_IMAGE_AS_COLOR);
$c->addSelectColumn(ProductOptionsValuePeer::USE_PRODUCT);
$c->addSelectColumn(ProductOptionsValuePeer::OLD_PRICE);
$c->addSelectColumn(ProductOptionsValuePeer::PUM);
$c->addSelectColumn(ProductOptionsValuePeer::DEPTH);
$c->addSelectColumn(ProductOptionsValuePeer::LFT);
$c->addSelectColumn(ProductOptionsValuePeer::RGT);
$c->addSelectColumn(ProductOptionsValuePeer::MAN_CODE);
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product->getId());
$c->addJoin(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID, ProductOptionsFieldPeer::ID, Criteria::LEFT_JOIN);
$c->addAscendingOrderByColumn(ProductOptionsValuePeer::LFT);
$rs = ProductOptionsValuePeer::doSelectRS($c);
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$combinations = array();
$paths = array();
$path = '';
$last_row = null;
$externalImages = $sf_context->getUser()->getAttribute('external_images', false, 'soteshop/stProduct/export');
if ($externalImages)
{
$request = $sf_context->getRequest();
$httpPrefix = stConfig::getInstance('stSecurityBackend')->get('ssl') == 'shop' ? 'https://' : 'http://';
$url = $httpPrefix . $request->getHost();
}
else
{
$url = '';
}
while($rs->next())
{
$row = $rs->getRow();
if ($row['DEPTH'] == 0)
{
$price_type = $row['PRICE_TYPE'];
if (null === $price_type)
{
$config = stConfig::getInstance('stProduct');
$price_type = $config->get('global_price_netto') ? 'netto' : 'brutto';
}
if ($product->getCurrencyExchange() != 1)
{
$price_type = 'brutto';
}
$combinations[] = self::getJsonFormat(array(self::getParamTranslation('price_type', $culture) => $price_type));
continue;
}
$depth = $row['DEPTH'];
$field = $row['PRODUCT_OPTIONS_FIELD_ID'];
if ($last_row && ($depth < $last_row['DEPTH'] || $last_row['PRODUCT_OPTIONS_FIELD_ID'] != $field && $last_row['RGT'] < $row['LFT']))
{
$path = '';
}
if ($row['PRODUCT_OPTIONS_FILTER_ID'])
{
$filter = self::getFilter($row['PRODUCT_OPTIONS_FILTER_ID']);
}
else
{
$filter = null;
}
if (!isset($paths[$field]))
{
$paths[$field] = $path ? $path.' | '.$row['OPT_NAME'] : $row['OPT_NAME'];
$combinations[] = $paths[$field] .' '. self::getJsonFormat(array(
self::getParamTranslation('filter', $culture) => $filter ? $filter->getOptName() : '',
self::getParamTranslation('default', $culture) => $row['OPT_DEFAULT_VALUE'] ? $row['OPT_DEFAULT_VALUE'] : $row['OPT_VALUE'],
self::getParamTranslation('id', $culture) => !$externalImages && null !== $row['PRODUCT_OPTIONS_FIELD_ID'] ? $row['PRODUCT_OPTIONS_FIELD_ID'] : '',
));
}
$path = $paths[$field].' | '.$row['OPT_VALUE'];
$last_row = $row;
if ($row['RGT'] - $row['LFT'] == 1)
{
$params = array(
self::getParamTranslation('price', $culture) => null !== $row['PRICE'] ? $row['PRICE'] : '',
self::getParamTranslation('old_price', $culture) => null !== $row['OLD_PRICE'] ? $row['OLD_PRICE'] : '',
self::getParamTranslation('stock', $culture) => null !== $row['STOCK'] ? $row['STOCK'] : '',
self::getParamTranslation('weight', $culture) => null !== $row['WEIGHT'] ? $row['WEIGHT'] : '',
self::getParamTranslation('code', $culture) => null !== $row['USE_PRODUCT'] ? $row['USE_PRODUCT'] : '',
self::getParamTranslation('pum', $culture) => null !== $row['PUM'] ? $row['PUM'] : '',
self::getParamTranslation('image', $culture) => $row['SF_ASSET_ID'] ? $row['SF_ASSET_ID'] : '',
self::getParamTranslation('man_code', $culture) => $row['MAN_CODE'] ? $row['MAN_CODE'] : '',
);
if ($filter && $filter->getFilterType() == 2)
{
if ($row['USE_IMAGE_AS_COLOR'])
{
$params[self::getParamTranslation('option_color', $culture)] = $url ? $url . ProductOptionsValuePeer::getColorImagePath($product->getId(), $row['ID'], $row['COLOR']) : $row['COLOR'];
}
else
{
$params[self::getParamTranslation('option_color', $culture)] = '#'.$row['COLOR'];
}
}
$params[self::getParamTranslation('id', $culture)] = !$externalImages && null !== $row['ID'] ? $row['ID'] : '';
$combinations[] = $path .' '. self::getJsonFormat($params);
}
else
{
$params = array(
self::getParamTranslation('price', $culture) => null !== $row['PRICE'] ? $row['PRICE'] : '',
self::getParamTranslation('old_price', $culture) => null !== $row['OLD_PRICE'] ? $row['OLD_PRICE'] : '',
self::getParamTranslation('weight', $culture) => null !== $row['WEIGHT'] ? $row['WEIGHT'] : '',
self::getParamTranslation('image', $culture) => $row['SF_ASSET_ID'] ? $row['SF_ASSET_ID'] : '',
self::getParamTranslation('id', $culture) => !$externalImages && null !== $row['ID'] ? $row['ID'] : '',
);
$combinations[] = $path .' '. self::getJsonFormat($params);
}
}
return $combinations ? implode("\n", $combinations) : '';
}
/**
* Ustawia opcji dla produktu
* @param $object - obiekt produktu
* @param $value - wartosc
* @return null
*/
public static function setProductOptions(Product $product, $value)
{
if ($value)
{
$combinations = explode("\n", $value);
$options = array();
self::$valid = true;
$price_type = null;
foreach ($combinations as $combination)
{
if (!trim($combination)) continue;
if (null === $price_type && strpos($combination, '{') !== false)
{
$params = self::decodeJsonFormat($combination);
if ($params)
{
$price_type = $params['price_type'];
continue;
}
}
$values = explode('|', $combination);
if (!$values) continue;
$current = array();
$params = array();
foreach ($values as $value)
{
if (strpos($value, '{') !== false)
{
$tmp = explode('{', $value);
$current[] = trim($tmp[0]);
$params = self::decodeJsonFormat('{'.$tmp[1]);
self::validateOptionsParams($product, $current, $params);
}
elseif (strpos($value, ':') !== false && preg_match('/:[^,]+,[^,]+,[^,]+,[^,]+/', $value))
{
stImportExportLog::getActiveLogger()->add($product->getCode(), sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Używasz starego formatu opcji produktu. <a href="http://www.sote.pl/trac/wiki/new_doc/products/import_export#Opisplikuimportueksportu" target="_blank">Zapoznaj się z nowym formatem</a>', array(
'%%option%%' => implode(' | ', $current)
), 'stProductOptionsBackend'), stImportExportLog::$WARNING);
self::$valid = false;
}
else
{
$current[] = trim($value);
}
}
$options[] = array('values' => $current, 'params' => $params);
}
if (!self::$valid)
{
throw new Exception(sfContext::getInstance()->getI18n()->__('Opcje nie zostały zaimportowane popraw powyższe błędy', null, 'stProductOptionsBackend'));
}
unset($combinations);
$keepIds = true;
$ids = array();
foreach ($options as $i => $option)
{
$is_field = ($i + 1) % 2;
if (!$is_field) {
if (isset($option['params']['id']))
{
$ids[] = $option['params']['id'];
}
}
}
if ($ids)
{
$c = new Criteria();
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product->getId());
$c->add(ProductOptionsValuePeer::ID, $ids, Criteria::IN);
$keepIds = ProductOptionsValuePeer::doCount($c);
}
$fields = array();
$values = array();
$con = Propel::getConnection();
$sql = sprintf('DELETE %1$s, %2$s, %3$s, %4$s FROM %1$s LEFT JOIN %3$s ON %5$s = %6$s, %2$s LEFT JOIN %4$s ON %7$s = %8$s WHERE %9$s = %7$s AND %10$s = ?',
ProductOptionsValuePeer::TABLE_NAME,
ProductOptionsFieldPeer::TABLE_NAME,
ProductOptionsValueI18nPeer::TABLE_NAME,
ProductOptionsFieldI18nPeer::TABLE_NAME,
ProductOptionsValuePeer::ID,
ProductOptionsValueI18nPeer::ID,
ProductOptionsFieldPeer::ID,
ProductOptionsFieldI18nPeer::ID,
ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID,
ProductOptionsValuePeer::PRODUCT_ID
);
$ps = $con->prepareStatement($sql);
$ps->setInteger(1, $product->getId());
$ps->executeQuery();
$root = self::getRootForProduct($product->getId());
$root->setLft(1);
$root->setRgt(2);
$root->_duplicated = true;
if (null === $price_type)
{
$config = stConfig::getInstance('stProduct');
$price_type = $config->get('global_price_netto') ? 'netto' : 'brutto';
}
if ($product->getCurrencyExchange() != 1)
{
$price_type = 'brutto';
}
$root->setPriceType($price_type);
$root->save();
$option_count = 0;
$culture = stLanguage::getOptLanguage();
foreach ($options as $index => $option)
{
$field = null;
$count = count($option['values']);
$croot = $root;
for ($i = 0; $i < $count; $i++)
{
$value = $option['values'][$i];
$is_field = ($i + 1) % 2;
$is_last = $i == $count - 1;
$namespace = ($field ? $field->getId() : '').$croot->getId().$value;
if ($is_field)
{
if (!isset($fields[$namespace]))
{
$field = new ProductOptionsField();
$field->setCulture($culture);
$field->setName($value);
if (isset($option['params']['filter']) && !empty($option['params']['filter']) && self::getFilter($option['params']['filter']))
{
$filter = self::getFilter($option['params']['filter'], true);
$field->setProductOptionsFilterId($filter->getId());
}
if (isset($option['params']['default']))
{
$field->setOptDefaultValue($option['params']['default']);
}
if ($keepIds && isset($option['params']['id']))
{
$field->setId($option['params']['id']);
}
$field->_duplicated = true;
$field->save();
$fields[$namespace] = $field;
}
elseif ($is_last)
{
stImportExportLog::getActiveLogger()->add($product->getCode(), sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Nazwa opcji została zdefiniowana już wcześniej (wiersz: %%row%%)', array(
'%%option%%' => implode(' | ', $option['values']),
'%%row%%' => $index + 1,
), 'stProductOptionsBackend'));
}
else
{
$field = $fields[$namespace];
}
}
else
{
if (!isset($values[$namespace]))
{
$pov = new ProductOptionsValue();
$pov->setCulture($culture);
$pov->setValue($value);
$pov->setProductOptionsField($field);
if ($field->getProductOptionsFilterId())
{
$pov->setOptFilterId($field->getProductOptionsFilterId());
}
if ($keepIds && isset($option['params']['id']))
{
$pov->setId($option['params']['id']);
}
if (isset($option['params']['price']))
{
$pov->setPrice($option['params']['price']);
}
if (isset($option['params']['old_price']))
{
$pov->setOldPrice($option['params']['old_price']);
}
if (isset($option['params']['stock']) && $option['params']['stock'] !== "")
{
$pov->setStock($option['params']['stock']);
}
if (isset($option['params']['weight']))
{
$pov->setWeight($option['params']['weight']);
}
if (isset($option['params']['code']))
{
$pov->setUseProduct($option['params']['code']);
}
if (isset($option['params']['man_code']))
{
$pov->setManCode($option['params']['man_code']);
}
if (isset($option['params']['pum']))
{
$pov->setPum($option['params']['pum']);
}
if (isset($option['params']['image']))
{
$pov->setSfAssetId($option['params']['image']);
}
if (isset($option['params']['option_color']))
{
$color = $option['params']['option_color'];
$pov->setUseImageAsColor($color[0] != '#');
if ($pov->getUseImageAsColor())
{
$pov->setColor($color);
}
else
{
$pov->setColor(ltrim($color, '#'));
}
}
elseif ($field->getProductOptionsFilterId() && self::getFilter($field->getProductOptionsFilterId()))
{
$filter = self::getFilter($field->getProductOptionsFilterId());
if ($filter->getFilterType() == 2)
{
$pov->setColor('ffffff');
}
}
$pov->_duplicated = true;
$croot = $croot->reload();
$pov->insertAsLastChildOf($croot);
$pov->save();
$option_count++;
if ($pov->getUseImageAsColor())
{
self::copyProductOptionsColorImage($product, $pov);
}
if (null == $field->getOptDefaultValue() || $field->getOptDefaultValue() == $value)
{
$field->getOptDefaultValue($value);
$field->setOptValueId($pov->getId());
$field->save();
}
$values[$namespace] = $pov;
$croot = $pov;
}
elseif ($is_last)
{
stImportExportLog::getActiveLogger()->add($product->getCode(), sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Wartość opcji została zdefiniowana już wcześniej (wiersz: %%row%%)', array(
'%%option%%' => implode(' | ', $option['values']),
'%%row%%' => $index + 1,
), 'stProductOptionsBackend'));
}
else
{
$croot = $values[$namespace];
}
}
}
}
self::cleanupProductOptionsColorImage($product);
$product->setOptHasOptions($option_count + 1);
$product->setStock(ProductOptionsValuePeer::updateStock($product, false));
ProductOptionsValuePeer::updateProductColor($product, false);
}
else
{
self::updateProductOptHasOptions($product, 0);
}
}
public static function updateStockForOptions(sfEvent $event)
{
$tmp = $event->getParameters();
$object = $tmp['modelInstance'];
ProductOptionsValuePeer::updateTotalStock($object->getId());
}
public static function updateProductOptHasOptions($product, $count = null)
{
$con = Propel::getConnection();
$sql = sprintf('UPDATE %1$s SET %2$s = ? WHERE %3$s = %4$s',
ProductPeer::TABLE_NAME,
ProductPeer::OPT_HAS_OPTIONS,
ProductPeer::ID,
$product->getId()
);
$st = $con->prepareStatement($sql);
$st->setInteger(1, null !== $count ? $count : $product->countProductOptionsValues());
$st->executeQuery();
}
public static function getJsonFormat($params)
{
return str_replace(array('":', '{', '}', ','), array('": ', '{ ', ' }', ', '), json_encode($params, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
}
public static function decodeJsonFormat($json)
{
return json_decode(trim(self::translateParams(str_replace(array('„', '“', '”'), array('"', '"', '"'), $json))), true);
}
public static function getFilter($id, $create = false)
{
if (!$id)
{
return null;
}
return is_numeric($id) ? ProductOptionsFilterPeer::retrieveById($id) : ProductOptionsFilterPeer::retrieveByName($id);
}
public static function jsonUnsecapedUnicode($matches)
{
return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');
}
protected static function imageExists(Product $product, $image_id)
{
$c = new Criteria();
$c->add(ProductHasSfAssetPeer::SF_ASSET_ID, $image_id);
$c->add(ProductHasSfAssetPeer::PRODUCT_ID, $product->getId());
return ProductHasSfAssetPeer::doCount($c);
}
protected static function checkProductOptionsColorImage(Product $product, &$filename, $current)
{
$product_id = $product->getId();
$is_url = false !== strpos($filename, '://');
if (!$is_url)
{
if (!isset(self::$productOptionsColorPool[$product_id]))
{
$images = array();
foreach (glob(ProductOptionsValuePeer::getColorImageDir($product_id, true).'/*') as $image)
{
list(,$name) = explode('-', basename($image), 2);
if(!isset($images[$name]))
{
$images[$name] = array();
}
$images[$name][] = $image;
}
self::$productOptionsColorPool[$product_id] = $images;
}
if (isset(self::$productOptionsColorPool[$product_id][$filename]))
{
return true;
}
$is_file = is_file(sfConfig::get('sf_upload_dir').'/assets/'.$filename);
if (!$is_file)
{
stImportExportLog::getActiveLogger()->add($product->getCode(), sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Zdjęcie "%%filename%%" nie zostało znalezione w katalogu "%%dir%%"', array(
'%%filename%%' => $filename,
'%%dir%%' => basename(sfConfig::get('sf_root_dir')).'/uploads/assets',
'%%option%%' => implode(' | ', $current)
), 'stProductOptionsBackend'), stImportExportLog::$WARNING);
}
return $is_file;
}
else
{
try
{
$file = stImportExportPropel::getFileContents($filename);
$filename = basename($file);
return true;
}
catch(Exception $e)
{
stImportExportLog::getActiveLogger()->add($product->getCode(), sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Wystąpił błąd przy próbie pobrania zdjęcia koloru (błąd: %%error%%)', array(
'%%option%%' => implode(' | ', $current),
'%%error%%' => $e->getMessage(),
), 'stProductOptionsBackend'));
}
}
return false;
}
protected static function copyProductOptionsColorImage(Product $product, ProductOptionsValue $pov)
{
$product_id = $product->getId();
$filename = $pov->getColor();
if (isset(self::$productOptionsColorPool[$product_id][$filename]))
{
$oldimagepath = array_pop(self::$productOptionsColorPool[$product_id][$filename]);
$newimagepath = $pov->getColorImagePath(true);
rename($oldimagepath, $newimagepath);
}
else
{
$oldimagepath = sfConfig::get('sf_upload_dir').'/assets/'.$filename;
$newimagepath = $pov->getColorImagePath(true);
$dir = dirname($newimagepath);
if (!is_dir($dir))
{
mkdir($dir, 0755, true);
}
copy($oldimagepath, $newimagepath);
}
}
protected static function cleanupProductOptionsColorImage(Product $product)
{
$product_id = $product->getId();
if (isset(self::$productOptionsColorPool[$product_id]))
{
foreach (self::$productOptionsColorPool[$product_id] as $images)
{
foreach ($images as $image)
{
unlink($image);
}
}
}
}
protected static function validateOptionsParams(Product $product, $current, &$params)
{
$code = $product->getCode();
if (!$params)
{
stImportExportLog::getActiveLogger()->add($code, sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Nieprawidłowy format parametrów dla opcji (poprawny: { "parametr": "wartość", "parametr": "wartość" })', array(
'%%option%%' => implode(' | ', $current)
), 'stProductOptionsBackend'), stImportExportLog::$WARNING);
self::$valid = false;
return;
}
$culture = sfContext::getInstance()->getUser()->getCulture();
if (isset($params['filter']) && !empty($params['filter']) && !self::getFilter($params['filter']))
{
if (is_numeric($params['filter']))
{
stImportExportLog::getActiveLogger()->add($code, sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Filtr opcji o id "%%id%%" nie istnieje', array(
'%%option%%' => implode(' | ', $current),
'%%id%%' => $params['filter'],
), 'stProductOptionsBackend'), stImportExportLog::$WARNING);
}
else
{
stImportExportLog::getActiveLogger()->add($code, sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Filtr opcji o nazwie "%%name%%" nie istnieje', array(
'%%option%%' => implode(' | ', $current),
'%%name%%' => $params['filter'],
), 'stProductOptionsBackend'), stImportExportLog::$WARNING);
}
self::$valid = false;
}
if (isset($params['option_color']) && $params['option_color'][0] != '#' && !self::checkProductOptionsColorImage($product, $params['option_color'], $current))
{
self::$valid = false;
}
if (isset($params['price']) && $params['price'] && !is_numeric(rtrim($params['price'], '%')))
{
stImportExportLog::getActiveLogger()->add($code, sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Nieprawidłowy format parametru "%%parameter%%" (poprawny: %%correct%%)', array(
'%%option%%' => implode(' | ', $current),
'%%parameter%%' => self::getParamTranslation('price', $culture),
'%%correct%%' => '+2%, -2.4, 2',
), 'stProductOptionsBackend'), stImportExportLog::$WARNING);
self::$valid = false;
}
if (isset($params['weight']) && $params['weight'] && !is_numeric(rtrim($params['weight'], '%')))
{
stImportExportLog::getActiveLogger()->add($code, sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Nieprawidłowy format parametru "%%parameter%%" (poprawny: %%correct%%)', array(
'%%option%%' => implode(' | ', $current),
'%%parameter%%' => self::getParamTranslation('weight', $culture),
'%%correct%%' => '+2%, -2.4, 2',
), 'stProductOptionsBackend'), stImportExportLog::$WARNING);
self::$valid = false;
}
if (isset($params['old_price']) && $params['old_price'] && (!is_numeric($params['old_price']) || $params['old_price'] < 0))
{
stImportExportLog::getActiveLogger()->add($code, sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Nieprawidłowy format parametru "%%parameter%%" (poprawny: %%correct%%)', array(
'%%option%%' => implode(' | ', $current),
'%%parameter%%' => self::getParamTranslation('old_price', $culture),
'%%correct%%' => '2, 2.4, 2.04',
), 'stProductOptionsBackend'), stImportExportLog::$WARNING);
self::$valid = false;
}
if (isset($params['stock']) && $params['stock'] !== "" && (!is_numeric($params['stock']) || $params['stock'] < 0))
{
stImportExportLog::getActiveLogger()->add($code, sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Nieprawidłowy format parametru "%%parameter%%" (poprawny: %%correct%%)', array(
'%%option%%' => implode(' | ', $current),
'%%parameter%%' => self::getParamTranslation('stock', $culture),
'%%correct%%' => '2, 2.4, 2.04',
), 'stProductOptionsBackend'), stImportExportLog::$WARNING);
self::$valid = false;
}
if (isset($params['image']) && $params['image'] && !self::imageExists($product, $params['image']))
{
stImportExportLog::getActiveLogger()->add($code, sfContext::getInstance()->getI18n()->__('<b>%%option%%:</b> Zdjęcie (parametr "%%parameter%%") produktu o podanym id "%%id%%" nie istnieje', array(
'%%option%%' => implode(' | ', $current),
'%%parameter%%' => self::getParamTranslation('image', $culture),
'%%id%%' => $params['image'],
), 'stProductOptionsBackend'), stImportExportLog::$WARNING);
self::$valid = false;
}
}
}

View File

@@ -0,0 +1,521 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class stProductOptionsPluginListener
{
static $postClear = array();
static $inBasket = array();
const DUPLICATE_LIMIT = 50;
/**
* Podpięcie zdarzenia do generatora produktu.
*
* @param sfEvent $event
*/
public static function generate(sfEvent $event)
{
// możemy wywoływać podaną metodę wielokrotnie co powoduje dołączenie kolejnych plików
$event->getSubject()->attachAdminGeneratorFile('stProductOptionsPlugin', 'stProduct.yml');
}
public static function productPreSave(sfEvent $event)
{
if ($event->getSubject()->isNew())
{
$event->getSubject()->setOptHasOptions($event->getSubject()->countProductOptionsValues());
}
}
public static function addOptionsFiltersFiltersCriteria(sfEvent $event)
{
$event['criteria']->add(ProductOptionsFilterPeer::FILTER_TYPE, 3, Criteria::NOT_EQUAL);
}
public static function productGetHasOptions(sfEvent $event)
{
if ($event->getSubject()->getOptHasOptions() !== null)
{
$event->setReturnValue($event->getSubject()->getOptHasOptions());
}
elseif (!$event->getSubject()->isNew())
{
$count = $event->getSubject()->countProductOptionsValues();
$con = Propel::getConnection();
$con->executeQuery(sprintf('UPDATE %s SET %s = %s WHERE %s = %s',
ProductPeer::TABLE_NAME,
ProductPeer::OPT_HAS_OPTIONS,
$count,
ProductPeer::ID,
$event->getSubject()->getId()
));
$event->setReturnValue($count);
}
return true;
}
public static function productPostExecuteDuplicate(sfEvent $event)
{
$duplicate = $event['duplicate'];
$product = $event['product'];
$duplicated_assets = $event['duplicated_assets'];
$default_culture = stLanguage::getOptLanguage();
$c = new Criteria();
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product->getId());
$c->addAscendingOrderByColumn(ProductOptionsValuePeer::LFT);
$count = ProductOptionsValuePeer::doCount($c);
if ($count > 1)
{
$fields = array();
$parents = array();
for ($offset = 0; $offset < $count; $offset += self::DUPLICATE_LIMIT)
{
$c->setOffset($offset);
$c->setLimit(self::DUPLICATE_LIMIT);
$options = ProductOptionsValuePeer::doSelect($c);
foreach ($options as $option)
{
$field_id = $option->getProductOptionsFieldId();
$duplicated_option = new ProductOptionsValue();
$option->copyInto($duplicated_option);
$asset_id = isset($duplicated_assets[$option->getSfAssetId()]) ? $duplicated_assets[$option->getSfAssetId()] : null;
if ($duplicated_option->getDepth() > 0)
{
$duplicated_option->setProductOptionsValueId($parents[$duplicated_option->getDepth() - 1]);
}
$duplicated_option->setProductId($duplicate->getId());
$duplicated_option->setSfAssetId($asset_id);
if ($field_id)
{
if (!isset($fields[$field_id]))
{
$field = $option->getProductOptionsField();
$duplicated_field = new ProductOptionsField();
$field->copyInto($duplicated_field);
$duplicated_field->save();
foreach ($field->getProductOptionsFieldI18ns() as $i18n)
{
if ($i18n->getCulture() != $default_culture)
{
$duplicated_i18n = new ProductOptionsFieldI18n();
$i18n->copyInto($duplicated_i18n);
$duplicated_i18n->setCulture($i18n->getCulture());
$duplicated_i18n->setId($duplicated_field->getId());
$duplicated_i18n->save();
}
}
$field->clearI18ns();
$fields[$field_id] = $duplicated_field->getId();
}
$duplicated_option->setProductOptionsFieldId($fields[$field_id]);
}
$duplicated_option->save();
if ($option->getUseImageAsColor())
{
if (!is_dir($duplicated_option->getColorImageDir(true)))
{
mkdir($duplicated_option->getColorImageDir(true), 0755, true);
}
copy($option->getColorImagePath(true), $duplicated_option->getColorImagePath(true));
}
foreach ($option->getProductOptionsValueI18ns() as $i18n)
{
if ($i18n->getCulture() != $default_culture)
{
$duplicated_i18n = new ProductOptionsValueI18n();
$i18n->copyInto($duplicated_i18n);
$duplicated_i18n->setCulture($i18n->getCulture());
$duplicated_i18n->setId($duplicated_option->getId());
$duplicated_i18n->save();
}
}
$option->clearI18ns();
if ($duplicated_option->hasChildren())
{
$parents[$duplicated_option->getDepth()] = $duplicated_option->getId();
}
}
unset($options);
}
$duplicate->setStock($product->getStock());
$duplicate->setOptHasOptions($product->getOptHasOptions());
$duplicate->save();
}
}
/**
*
* @param sfEvent $event
*/
public static function preExecuteOptionsEdit(sfEvent $event)
{
$subject = $event->getSubject();
if(!$subject->getRequest()->hasParameter('id'))
{
$forward_parameters = $subject->getUser()->getAttributeHolder()->getAll('sf_admin/autoStProduct/options_forward_parameters');
$subject->redirectIf(isset($forward_parameters['id']), 'stProduct/optionsEdit?id='.$forward_parameters['id']);
}
}
/**
* Podpięcie zdarzenia dla edycji opcji produktu.
*
* @param sfEvent $event
*/
public static function postExecuteOptionsEdit(sfEvent $event)
{
$product_id = $event->getSubject()->getRequestParameter('id');
//fix w przypadku zmiany wartosci opcji
$c = new Criteria();
$c->add(ProductOptionsValuePeer::OPT_VERSION, ProductOptionsValuePeer::version, Criteria::NOT_EQUAL);
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product_id);
$all_options = ProductOptionsValuePeer::doSelect($c);
foreach ($all_options as $option)
{
$option->save();
}
$user = $event->getSubject()->getUser();
if($user->hasAttribute('remeber', 'symfony/user/sfUser/attributes'))
{
$user->getAttributeHolder()->remove('remeber', 'symfony/user/sfUser/attributes');
$product_id = empty($product_id) ? $user->getAttribute('id') : $product_id;
$event->getSubject()->redirect('stProduct/optionsEdit?id='.$product_id);
}
$c = new Criteria();
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product_id);
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_VALUE_ID, null, Criteria::ISNULL);
$root = ProductOptionsValuePeer::doSelectOne($c);
if(!$root)
{
$root = new ProductOptionsValue();
$root->setProductId($product_id);
$root->makeRoot();
$root->save();
}
$event->getSubject()->getContext()->root = $root;
}
/**
* Podpięcie zdarzenia dla edycji szablonów opcji.
*
* @param sfEvent $event
*/
public static function preExecuteOptionsTemplatesEdit(sfEvent $event)
{
$id = $event->getSubject()->getRequestParameter('id');
if($event->getSubject()->getRequest()->hasParameter('remeber'))
{
$event->getSubject()->getUser()->setAttribute('remeber', 1);
$event->getSubject()->redirect('stProduct/optionsTemplatesCreate');
}
if($id)
{
$c = new Criteria();
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_TEMPLATE_ID, $id);
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_DEFAULT_VALUE_ID, null, Criteria::ISNULL);
$root = ProductOptionsDefaultValuePeer::doSelectOne($c);
if($root === null)
{
$root = new ProductOptionsDefaultValue();
$root->setProductOptionsTemplateId($id);
$root->setPriceType('netto');
$root->makeRoot();
$root->save();
}
$event->getSubject()->getContext()->root = $root;
}
}
/**
* Funkcja wywoływana przed wyświetleniem listy szablonów opcji.
* Usuwa szablony które nie mają określonej nazwy.
*
* @param sfEvent $event
*/
public static function preExecuteOptionsTemplatesList(sfEvent $event)
{
if($event->getSubject()->getRequest()->hasParameter('remeber'))
{
$event->getSubject()->getUser()->setAttribute('remeber', 1);
$event->getSubject()->redirect('stProduct/optionsTemplatesList');
}
}
/**
* Usuwa produkt z koszyka oznaczony przez funkcję modBasketExecuteAddItem()
*
* @param sfEvent $event
*/
public static function postBasketExecuteAddItem(sfEvent $event)
{
if($event->getSubject()->getItem(-1))
{
$event->getSubject()->removeItem(-1);
}
}
/**
*
*
* @param sfEvent $event
*/
public static function filterMirrorOrderProduct(sfEvent $event)
{
$event['order_product']->setOptions($event['basket_product']->getOptions());
return $event['order_product'];
}
/**
* Tworzy łańcuch znaków z tablicy zawierającej idki opcji dla produktu.
*
* @param $options_ids - tablica id opcji
*/
public static function createStringOptions($options_ids)
{
if(!empty($options_ids))
{
$result = '<ul>';
foreach($options_ids as $option_id)
{
$option = ProductOptionsValuePeer::retrieveByPk($option_id);
$result .= '<li>'.$option->getValue().'</li>';
if($option->isLeaf())
{
$id = $option->getId();
}
}
$result .= '</ul>';
return $result;
}
}
public static function productPostExecuteShow(sfEvent $event)
{
$action = $event->getSubject();
$product = $action->product;
if ($product->getOptHasOptions() > 0)
{
ProductOptionsValue::setProductPool($product);
stNewProductOptions::updateProduct($product);
}
}
public static function basketGenerateItemId(sfEvent $event, $id)
{
$ids = self::getRequest()->getParameter('option_list');
if ($ids && $id == self::getRequest()->getParameter('product_id'))
{
return md5($id.$ids);
}
return $id;
}
public static function basketModAddItem(sfEvent $event)
{
$item = $event['item'];
$product = $event['product'];
$ids = self::getRequest()->getParameter('option_list');
if ($ids)
{
ProductOptionsValue::setProductPool($product);
$ids = explode('-', $ids);
$options = ProductOptionsValuePeer::retrieveByPKs($ids);
$price_type = ProductOptionsValuePeer::getPriceType($product);
$image = null;
$stock = $item->getMaxQuantity();
foreach ($ids as $id)
{
foreach ($options as $option)
{
if ($option->getId() == $id) break;
}
stNewProductOptions::addProductPriceModifier($item, $option->getPrice(), $option->getDepth(), $price_type, array('id' => $option->getId(), 'label' => $option->getValue(), 'type' => 'product_options'));
if ($option->getUseProduct())
{
$item->setCode($option->getUseProduct());
}
if ($option->getsfAssetId())
{
$image = $option->getsfAssetId();
}
if (null !== $option->getStock() && $stock > $option->getStock())
{
$stock = $option->getStock();
}
}
if ($image && ($sf_asset = sfAssetPeer::retrieveByPK($image)))
{
$item->setImage($sf_asset->getRelativePath());
}
if ($stock)
{
$item->setMaxQuantity($stock);
}
}
}
public static function preBasketExecuteAddItem(sfEvent $event)
{
if (sfContext::getInstance()->getRequest()->hasParameter('options_list'))
ProductOptionsValuePeer::setSelectedItems($event['id_product'], explode('-',sfContext::getInstance()->getRequest()->getParameter('options_list')));
}
public static function getRequest()
{
static $request = null;
if (null === $request)
{
$request = sfContext::getInstance()->getRequest();
}
return $request;
}
public static function postAddItem(sfEvent $event)
{
if (!empty(self::$postClear['item'])) {
stBasket::getInstance(sfContext::getInstance()->getUser())->updateItem(self::$postClear['item'], self::$postClear['quantity']);
}
}
public static function postInstall(sfEvent $event)
{
sfLoader::loadHelpers('stProgressBar');
sfLoader::loadHelpers('Partial');
stProductOptionsFix::initDatabase();
$count = stProductOptionsFix::count();
stProductOptionsFix::shutdownDatabase();
$event->getSubject()->msg .= progress_bar('stProductOptionsFix', 'stProductOptionsFix', 'executeUpdate', $count);
}
public static function postExecuteFilter(sfEvent $event)
{
$action = $event->getSubject();
if ($action->getRequest()->getMethod() == sfRequest::POST && $action->hasRequestParameter('options_filters'))
{
$options_filters = $action->getRequestParameter('options_filters');
stNewProductOptions::setFilters($action->getContext(), $options_filters);
}
}
public static function postExecuteClearFilter(sfEvent $event)
{
$action = $event->getSubject();
if ($action->getRequestParameter('scope') == 'options')
{
$filter = $action->getRequestParameter('filter');
$filters = stNewProductOptions::getFilters($action->getContext());
if ('all' == $filter)
{
stNewProductOptions::clearFilters($action->getContext());
}
elseif (isset($filters[$filter]))
{
unset($filters[$filter]);
stNewProductOptions::setFilters($action->getContext(), $filters);
}
}
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* SOTESHOP/stProductOptionsPlugin
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stProductOptionsPlugin
* @subpackage libs
*/
class stProductOptionsStockListener
{
public static function updateOptionsStockListItem(sfEvent $event)
{
$request = $event->getSubject()->getRequestParameter('product_options_value');
$option = $event['modelInstance'];
if ($request[$option->getId()]['disabled'])
{
$option->setStock(null);
}
}
public static function postExecuteOptionsStockList(sfEvent $event)
{
$action = $event->getSubject();
$c = $action->pager->getCriteria();
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $action->forward_parameters['id']);
$action->pager->init();
$action->getUser()->setAttribute('optionsStockList.mode', 'edit', 'soteshop/stAdminGenerator/stProduct/config');
}
public static function preExecuteOptionsStockDelete(sfEvent $event)
{
$options = $event->getSubject()->getRequest()->getParameter('product_options_value');
$value = $event->getSubject()->getRequest()->getParameter('value', null);
if(count($options['selected']) > 0)
{
foreach($options['selected'] as $selected)
{
$option = ProductOptionsValuePeer::retrieveByPk($selected);
$option->setStock($value);
$option->save();
}
$product = $option->getProduct();
foreach($product->getProductOptionsValues() as $option)
{
if(empty($total))
{
$total = $option->getStock();
}
else
{
$total += $option->getStock();
}
}
if(empty($total))
{
$product->setStock(null);
}
else
{
$product->setStock($total);
}
$product->save();
$event->getSubject()->getRequest()->setParameter('product_options_value', array('selected' => array()));
}
$request = $event->getSubject()->getRequest();
$params = '?id='.$request->getParameter('id');
if($request->hasParameter('page'))
{
$params .= '&page='.$request->getParameter('page');
}
$event->getSubject()->redirect('stProduct/optionsStockList'.$params);
}
public static function postProductSave(sfEvent $event) {
$product = $event['modelInstance'];
if ($product->getOptHasOptions()>1 && $event->getSubject()->getRequestParameter('product[is_depository]')==1) {
$product->setStock(ProductOptionsValuePeer::getProductOptionsStock($product));
$product->resetModifiers();
}
}
public static function clearFastCache()
{
stFastCacheManager::clearCache();
}
public static function validateProductConfig(sfEvent $event,$args) {
$context = sfContext::getInstance();
$request = $context->getRequest();
if ($request->getMethod() == sfRequest::POST && $request->hasParameter('config[nb_colors_on_list]')) {
if (intval($request->getParameter('config[nb_colors_on_list]'))<0 || !is_numeric($request->getParameter('config[nb_colors_on_list]'))) {
$request->setError('config{nb_colors_on_list}',$context->getI18n()->__('Proszę podać liczbę całkowitą nieujemną',null,'stProductOptionsBackend'));
$args = false;
}
}
return $args;
}
}

View File

@@ -0,0 +1,50 @@
<?php
class stProductOptionsStockUpdateComputationProgressBarTask extends stProgressBarTask
{
const LIMIT = 40;
public function execute($offset)
{
$c = $this->getCriteria();
$c->setLimit(self::LIMIT);
$c->setOffset($offset);
$this->setMessage($this->getI18N()->__('Aktualizacja stanów magazynowych w toku...', null, 'stProductOptionsBackend'));
foreach (ProductPeer::doSelectIds($c) as $id)
{
ProductOptionsValuePeer::updateStock($id);
$offset++;
usleep(20000);
}
return $offset;
}
public function count()
{
return ProductPeer::doCount($this->getCriteria());
}
public function finished()
{
sfLoader::loadHelpers(['Helper', 'stAdminGenerator']);
$message = $this->getI18N()->__('Stany magazynowe zaktualizowane pomyślnie.', null, 'stProductOptionsBackend') . '<br>' . st_get_admin_button('default', $this->getI18N()->__('Powrót'), '@stProduct?action=config');
$this->setMessage($message);
stPartialCache::clear('stProduct', '_productGroup', array('app' => 'frontend'));
stPartialCache::clear('stProduct', '_new', array('app' => 'frontend'));
stFastCacheManager::clearCache();
}
protected function getCriteria(): Criteria
{
$c = new Criteria();
$c->add(ProductPeer::OPT_HAS_OPTIONS, 1, Criteria::GREATER_THAN);
$c->add(ProductPeer::STOCK_MANAGMENT, ProductPeer::STOCK_PRODUCT_OPTIONS);
return $c;
}
}