getConditions() as $condition) {
/** @var $condition Mage_Rule_Model_Condition_Abstract */
$wheres[] = $condition->prepareConditionSql();
}
if (empty($wheres)) {
return '';
}
$delimiter = $this->getAggregator() == "all" ? ' AND ' : ' OR ';
return ' (' . implode($delimiter, $wheres) . ') ';
}
/**
* Retrieve new object for each requested model.
* If model is requested first time, store it at static array.
*
* It's made by performance reasons to avoid initialization of same models each time when rules are being processed.
*
* @param string $modelClass
* @return Mage_Rule_Model_Condition_Abstract|bool
*/
protected function _getNewConditionModelInstance($modelClass)
{
if (empty($modelClass)) {
return false;
}
if (!array_key_exists($modelClass, self::$_conditionModels)) {
$model = Mage::getModel($modelClass);
self::$_conditionModels[$modelClass] = $model;
} else {
$model = self::$_conditionModels[$modelClass];
}
if (!$model) {
return false;
}
$newModel = clone $model;
return $newModel;
}
public function __construct()
{
parent::__construct();
$this->setType('rule/condition_combine')
->setAggregator('all')
->setValue(true)
->setConditions(array())
->setActions(array());
$this->loadAggregatorOptions();
if ($options = $this->getAggregatorOptions()) {
foreach ($options as $aggregator=>$dummy) { $this->setAggregator($aggregator); break; }
}
}
/* start aggregator methods */
public function loadAggregatorOptions()
{
$this->setAggregatorOption(array(
'all' => Mage::helper('rule')->__('ALL'),
'any' => Mage::helper('rule')->__('ANY'),
));
return $this;
}
public function getAggregatorSelectOptions()
{
$opt = array();
foreach ($this->getAggregatorOption() as $k=>$v) {
$opt[] = array('value'=>$k, 'label'=>$v);
}
return $opt;
}
public function getAggregatorName()
{
return $this->getAggregatorOption($this->getAggregator());
}
public function getAggregatorElement()
{
if (is_null($this->getAggregator())) {
foreach ($this->getAggregatorOption() as $k=>$v) {
$this->setAggregator($k);
break;
}
}
return $this->getForm()->addField($this->getPrefix().'__'.$this->getId().'__aggregator', 'select', array(
'name'=>'rule['.$this->getPrefix().']['.$this->getId().'][aggregator]',
'values'=>$this->getAggregatorSelectOptions(),
'value'=>$this->getAggregator(),
'value_name'=>$this->getAggregatorName(),
))->setRenderer(Mage::getBlockSingleton('rule/editable'));
}
/* end aggregator methods */
public function loadValueOptions()
{
$this->setValueOption(array(
1 => Mage::helper('rule')->__('TRUE'),
0 => Mage::helper('rule')->__('FALSE'),
));
return $this;
}
public function addCondition($condition)
{
$condition->setRule($this->getRule());
$condition->setObject($this->getObject());
$condition->setPrefix($this->getPrefix());
$conditions = $this->getConditions();
$conditions[] = $condition;
if (!$condition->getId()) {
$condition->setId($this->getId().'--'.sizeof($conditions));
}
$this->setData($this->getPrefix(), $conditions);
return $this;
}
public function getValueElementType()
{
return 'select';
}
/**
* Returns array containing conditions in the collection
*
* Output example:
* array(
* 'type'=>'combine',
* 'operator'=>'ALL',
* 'value'=>'TRUE',
* 'conditions'=>array(
* {condition::asArray},
* {combine::asArray},
* {quote_item_combine::asArray}
* )
* )
*
* @return array
*/
public function asArray(array $arrAttributes = array())
{
$out = parent::asArray();
$out['aggregator'] = $this->getAggregator();
foreach ($this->getConditions() as $condition) {
$out['conditions'][] = $condition->asArray();
}
return $out;
}
public function asXml($containerKey='conditions', $itemKey='condition')
{
$xml = "