Files
grzanieplus.pl/plugins/stProductOptionsPlugin/lib/model/ProductOptionsFieldPeer.php
2025-03-12 17:06:23 +01:00

136 lines
4.2 KiB
PHP

<?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;
}
}