Mage_Rule_Model_Condition_Combine Class Reference

Inheritance diagram for Mage_Rule_Model_Condition_Combine:

Mage_Rule_Model_Condition_Abstract Varien_Object Mage_Rule_Model_Condition_Interface Mage_CatalogRule_Model_Rule_Condition_Combine Mage_SalesRule_Model_Rule_Condition_Combine Mage_SalesRule_Model_Rule_Condition_Product_Combine Mage_SalesRule_Model_Rule_Condition_Product_Found Mage_SalesRule_Model_Rule_Condition_Product_Subselect

List of all members.

Public Member Functions

 __construct ()
 loadAggregatorOptions ()
 getAggregatorSelectOptions ()
 getAggregatorName ()
 getAggregatorElement ()
 loadValueOptions ()
 addCondition ($condition)
 getValueElementType ()
 asArray (array $arrAttributes=array())
 asXml ($containerKey='conditions', $itemKey='condition')
 loadArray ($arr, $key='conditions')
 loadXml ($xml)
 asHtml ()
 getNewChildElement ()
 asHtmlRecursive ()
 asString ($format='')
 asStringRecursive ($level=0)
 validate (Varien_Object $object)
 setJsFormObject ($form)
 getConditions ()


Detailed Description

Definition at line 28 of file Combine.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor

By default is looking for first argument as array and assignes it as object attributes This behaviour may change in child classes

Reimplemented from Mage_Rule_Model_Condition_Abstract.

Reimplemented in Mage_CatalogRule_Model_Rule_Condition_Combine, Mage_SalesRule_Model_Rule_Condition_Combine, Mage_SalesRule_Model_Rule_Condition_Product_Combine, Mage_SalesRule_Model_Rule_Condition_Product_Found, and Mage_SalesRule_Model_Rule_Condition_Product_Subselect.

Definition at line 30 of file Combine.php.

00031     {
00032         parent::__construct();
00033         $this->setType('rule/condition_combine')
00034             ->setAggregator('all')
00035             ->setValue(true)
00036             ->setConditions(array())
00037             ->setActions(array());
00038 
00039 
00040         $this->loadAggregatorOptions();
00041         if ($options = $this->getAggregatorOptions()) {
00042             foreach ($options as $aggregator=>$dummy) { $this->setAggregator($aggregator); break; }
00043         }
00044     }


Member Function Documentation

addCondition ( condition  ) 

Definition at line 95 of file Combine.php.

00096     {
00097         $condition->setRule($this->getRule());
00098         $condition->setObject($this->getObject());
00099         $condition->setPrefix($this->getPrefix());
00100 
00101         $conditions = $this->getConditions();
00102         $conditions[] = $condition;
00103 
00104         if (!$condition->getId()) {
00105             $condition->setId($this->getId().'--'.sizeof($conditions));
00106         }
00107 
00108         $this->setData($this->getPrefix(), $conditions);
00109         return $this;
00110     }

asArray ( array arrAttributes = array()  ) 

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} ) )

Returns:
array

Reimplemented from Mage_Rule_Model_Condition_Abstract.

Definition at line 134 of file Combine.php.

00135     {
00136         $out = parent::asArray();
00137         $out['aggregator'] = $this->getAggregator();
00138 
00139         foreach ($this->getConditions() as $condition) {
00140             $out['conditions'][] = $condition->asArray();
00141         }
00142 
00143         return $out;
00144     }

asHtml (  ) 

Reimplemented from Mage_Rule_Model_Condition_Abstract.

Reimplemented in Mage_SalesRule_Model_Rule_Condition_Product_Found, and Mage_SalesRule_Model_Rule_Condition_Product_Subselect.

Definition at line 192 of file Combine.php.

00193     {
00194            $html = $this->getTypeElement()->getHtml().
00195                Mage::helper('rule')->__("If %s of these conditions are %s:",
00196                    $this->getAggregatorElement()->getHtml(),
00197                    $this->getValueElement()->getHtml()
00198                );
00199            if ($this->getId()!='1') {
00200                $html.= $this->getRemoveLinkHtml();
00201            }
00202         return $html;
00203     }

asHtmlRecursive (  ) 

Reimplemented from Mage_Rule_Model_Condition_Abstract.

Definition at line 214 of file Combine.php.

00215     {
00216         $html = $this->asHtml().'<ul id="'.$this->getPrefix().'__'.$this->getId().'__children" class="rule-param-children">';
00217         foreach ($this->getConditions() as $cond) {
00218             $html .= '<li>'.$cond->asHtmlRecursive().'</li>';
00219         }
00220         $html .= '<li>'.$this->getNewChildElement()->getHtml().'</li></ul>';
00221         return $html;
00222     }

asString ( format = ''  ) 

Reimplemented from Mage_Rule_Model_Condition_Abstract.

Definition at line 224 of file Combine.php.

00225     {
00226         $str = Mage::helper('rule')->__("If %s of these conditions are %s:", $this->getAggregatorName(), $this->getValueName());
00227         return $str;
00228     }

asStringRecursive ( level = 0  ) 

Reimplemented from Mage_Rule_Model_Condition_Abstract.

Definition at line 230 of file Combine.php.

00231     {
00232         $str = parent::asStringRecursive($level);
00233         foreach ($this->getConditions() as $cond) {
00234             $str .= "\n".$cond->asStringRecursive($level+1);
00235         }
00236         return $str;
00237     }

asXml ( containerKey = 'conditions',
itemKey = 'condition' 
)

Reimplemented in Mage_SalesRule_Model_Rule_Condition_Product_Subselect.

Definition at line 146 of file Combine.php.

00147     {
00148         $xml = "<aggregator>".$this->getAggregator()."</aggregator>"
00149             ."<value>".$this->getValue()."</value>"
00150             ."<$containerKey>";
00151         foreach ($this->getConditions() as $condition) {
00152             $xml .= "<$itemKey>".$condition->asXml()."</$itemKey>";
00153         }
00154         $xml .= "</$containerKey>";
00155         return $xml;
00156     }

getAggregatorElement (  ) 

Definition at line 69 of file Combine.php.

00070     {
00071         if (is_null($this->getAggregator())) {
00072             foreach ($this->getAggregatorOption() as $k=>$v) {
00073                 $this->setAggregator($k);
00074                 break;
00075             }
00076         }
00077         return $this->getForm()->addField($this->getPrefix().'__'.$this->getId().'__aggregator', 'select', array(
00078             'name'=>'rule['.$this->getPrefix().']['.$this->getId().'][aggregator]',
00079             'values'=>$this->getAggregatorSelectOptions(),
00080             'value'=>$this->getAggregator(),
00081             'value_name'=>$this->getAggregatorName(),
00082         ))->setRenderer(Mage::getBlockSingleton('rule/editable'));
00083     }

getAggregatorName (  ) 

Definition at line 64 of file Combine.php.

00065     {
00066         return $this->getAggregatorOption($this->getAggregator());
00067     }

getAggregatorSelectOptions (  ) 

Definition at line 55 of file Combine.php.

00056     {
00057         $opt = array();
00058         foreach ($this->getAggregatorOption() as $k=>$v) {
00059             $opt[] = array('value'=>$k, 'label'=>$v);
00060         }
00061         return $opt;
00062     }

getConditions (  ) 

Definition at line 269 of file Combine.php.

00270     {
00271         return $this->getData($this->getPrefix());
00272     }

getNewChildElement (  ) 

Definition at line 205 of file Combine.php.

00206     {
00207         return $this->getForm()->addField($this->getPrefix().'__'.$this->getId().'__new_child', 'select', array(
00208             'name'=>'rule['.$this->getPrefix().']['.$this->getId().'][new_child]',
00209             'values'=>$this->getNewChildSelectOptions(),
00210             'value_name'=>$this->getNewChildName(),
00211         ))->setRenderer(Mage::getBlockSingleton('rule/newchild'));
00212     }

getValueElementType (  ) 

Value element type will define renderer for condition value element

See also:
Varien_Data_Form_Element
Returns:
string

Reimplemented from Mage_Rule_Model_Condition_Abstract.

Reimplemented in Mage_SalesRule_Model_Rule_Condition_Product_Subselect.

Definition at line 112 of file Combine.php.

00113     {
00114         return 'select';
00115     }

loadAggregatorOptions (  ) 

Definition at line 46 of file Combine.php.

00047     {
00048         $this->setAggregatorOption(array(
00049             'all' => Mage::helper('rule')->__('ALL'),
00050             'any' => Mage::helper('rule')->__('ANY'),
00051         ));
00052         return $this;
00053     }

loadArray ( arr,
key = 'conditions' 
)

Reimplemented in Mage_SalesRule_Model_Rule_Condition_Product_Subselect.

Definition at line 158 of file Combine.php.

00159     {
00160         $this->setAggregator(isset($arr['aggregator']) ? $arr['aggregator'] : $arr['attribute'])
00161             ->setValue(isset($arr['value']) ? $arr['value'] : $arr['operator']);
00162 
00163         if (!empty($arr[$key]) && is_array($arr[$key])) {
00164             foreach ($arr[$key] as $condArr) {
00165                 try {
00166                     $cond = @Mage::getModel($condArr['type']);
00167                     if (!empty($cond)) {
00168                         $this->addCondition($cond);
00169                         $cond->loadArray($condArr, $key);
00170                     }
00171                 } catch (Exception $e) {
00172 
00173                 }
00174             }
00175         }
00176         return $this;
00177     }

loadValueOptions (  ) 

Reimplemented from Mage_Rule_Model_Condition_Abstract.

Reimplemented in Mage_SalesRule_Model_Rule_Condition_Product_Found.

Definition at line 86 of file Combine.php.

00087     {
00088         $this->setValueOption(array(
00089             1 => Mage::helper('rule')->__('TRUE'),
00090             0 => Mage::helper('rule')->__('FALSE'),
00091         ));
00092         return $this;
00093     }

loadXml ( xml  ) 

Reimplemented from Mage_Rule_Model_Condition_Abstract.

Definition at line 179 of file Combine.php.

00180     {
00181         if (is_string($xml)) {
00182             $xml = simplexml_load_string($xml);
00183         }
00184         $arr = parent::loadXml($xml);
00185         foreach ($xml->conditions->children() as $condition) {
00186             $arr['conditions'] = parent::loadXml($condition);
00187         }
00188         $this->loadArray($arr);
00189         return $this;
00190     }

setJsFormObject ( form  ) 

Definition at line 260 of file Combine.php.

00261     {
00262         $this->setData('js_form_object', $form);
00263         foreach ($this->getConditions() as $condition) {
00264             $condition->setJsFormObject($form);
00265         }
00266         return $this;
00267     }

validate ( Varien_Object object  ) 

Reimplemented from Mage_Rule_Model_Condition_Abstract.

Reimplemented in Mage_SalesRule_Model_Rule_Condition_Product_Found, and Mage_SalesRule_Model_Rule_Condition_Product_Subselect.

Definition at line 239 of file Combine.php.

00240     {
00241         if (!$this->getConditions()) {
00242             return true;
00243         }
00244 
00245         $all    = $this->getAggregator() === 'all';
00246         $true   = (bool)$this->getValue();
00247 
00248         foreach ($this->getConditions() as $cond) {
00249             $validated = $cond->validate($object);
00250 
00251             if ($all && $validated !== $true) {
00252                 return false;
00253             } elseif (!$all && $validated === $true) {
00254                 return true;
00255             }
00256         }
00257         return $all ? true : false;
00258     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:39 2009 for Magento by  doxygen 1.5.8