Mage_Rule_Model_Condition_Abstract Class Reference

Inheritance diagram for Mage_Rule_Model_Condition_Abstract:

Varien_Object Mage_Rule_Model_Condition_Interface Mage_CatalogRule_Model_Rule_Condition_Product Mage_Rule_Model_Condition_Combine Mage_SalesRule_Model_Rule_Condition_Address Mage_SalesRule_Model_Rule_Condition_Product 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 ()
 getForm ()
 asArray (array $arrAttributes=array())
 asXml ()
 loadArray ($arr)
 loadXml ($xml)
 loadAttributeOptions ()
 getAttributeOptions ()
 getAttributeSelectOptions ()
 getAttributeName ()
 loadOperatorOptions ()
 getInputType ()
 getOperatorSelectOptions ()
 getOperatorName ()
 loadValueOptions ()
 getValueSelectOptions ()
 getValueParsed ()
 getValue ()
 getValueName ()
 getNewChildSelectOptions ()
 getNewChildName ()
 asHtml ()
 asHtmlRecursive ()
 getTypeElement ()
 getTypeElementHtml ()
 getAttributeElement ()
 getAttributeElementHtml ()
 getOperatorElement ()
 getOperatorElementHtml ()
 getValueElementType ()
 getValueElementRenderer ()
 getValueElement ()
 getValueElementHtml ()
 getAddLinkHtml ()
 getRemoveLinkHtml ()
 getChooserContainerHtml ()
 asString ($format='')
 asStringRecursive ($level=0)
 validateAttribute ($validatedValue)
 validate (Varien_Object $object)


Detailed Description

Abstract class for quote rule condition

Definition at line 32 of file Abstract.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 Varien_Object.

Reimplemented in Mage_CatalogRule_Model_Rule_Condition_Combine, Mage_Rule_Model_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 36 of file Abstract.php.

00037     {
00038         parent::__construct();
00039 
00040         $this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions();
00041 
00042         if ($options = $this->getAttributeOptions()) {
00043             foreach ($options as $attr=>$dummy) { $this->setAttribute($attr); break; }
00044         }
00045         if ($options = $this->getOperatorOptions()) {
00046             foreach ($options as $operator=>$dummy) { $this->setOperator($operator); break; }
00047         }
00048     }


Member Function Documentation

asArray ( array arrAttributes = array()  ) 

Reimplemented in Mage_Rule_Model_Condition_Combine.

Definition at line 55 of file Abstract.php.

00056     {
00057         $out = array(
00058             'type'=>$this->getType(),
00059             'attribute'=>$this->getAttribute(),
00060             'operator'=>$this->getOperator(),
00061             'value'=>$this->getValue(),
00062             'is_value_processed'=>$this->getIsValueParsed(),
00063         );
00064         return $out;
00065     }

asHtml (  ) 

Reimplemented in Mage_Rule_Model_Condition_Combine, Mage_SalesRule_Model_Rule_Condition_Product_Found, and Mage_SalesRule_Model_Rule_Condition_Product_Subselect.

Definition at line 269 of file Abstract.php.

00270     {
00271         $html = $this->getTypeElementHtml()
00272            .$this->getAttributeElementHtml()
00273            .$this->getOperatorElementHtml()
00274            .$this->getValueElementHtml()
00275            .$this->getRemoveLinkHtml()
00276            .$this->getChooserContainerHtml();
00277         return $html;
00278     }

asHtmlRecursive (  ) 

Reimplemented in Mage_Rule_Model_Condition_Combine.

Definition at line 280 of file Abstract.php.

00281     {
00282         $html = $this->asHtml();
00283         return $html;
00284     }

asString ( format = ''  ) 

Reimplemented in Mage_Rule_Model_Condition_Combine.

Definition at line 412 of file Abstract.php.

00413     {
00414         $str = $this->getAttributeName().' '.$this->getOperatorName().' '.$this->getValueName();
00415         return $str;
00416     }

asStringRecursive ( level = 0  ) 

Reimplemented in Mage_Rule_Model_Condition_Combine.

Definition at line 418 of file Abstract.php.

00419     {
00420         $str = str_pad('', $level*3, ' ', STR_PAD_LEFT).$this->asString();
00421         return $str;
00422     }

asXml (  ) 

Definition at line 67 of file Abstract.php.

00068     {
00069         $xml = "<type>".$this->getType()."</type>"
00070             ."<attribute>".$this->getAttribute()."</attribute>"
00071             ."<operator>".$this->getOperator()."</operator>"
00072             ."<value>".$this->getValue()."</value>";
00073         return $xml;
00074     }

getAddLinkHtml (  ) 

Definition at line 388 of file Abstract.php.

00389     {
00390         $src = Mage::getDesign()->getSkinUrl('images/rule_component_add.gif');
00391         $html = '<img src="'.$src.'" class="rule-param-add v-middle" alt="" title="'.Mage::helper('rule')->__('Add').'"/>';
00392         return $html;
00393     }

getAttributeElement (  ) 

Reimplemented in Mage_CatalogRule_Model_Rule_Condition_Product, and Mage_SalesRule_Model_Rule_Condition_Address.

Definition at line 301 of file Abstract.php.

00302     {
00303         if (is_null($this->getAttribute())) {
00304             foreach ($this->getAttributeOption() as $k=>$v) {
00305                 $this->setAttribute($k);
00306                 break;
00307             }
00308         }
00309         return $this->getForm()->addField($this->getPrefix().'__'.$this->getId().'__attribute', 'select', array(
00310             'name'=>'rule['.$this->getPrefix().']['.$this->getId().'][attribute]',
00311             'values'=>$this->getAttributeSelectOptions(),
00312             'value'=>$this->getAttribute(),
00313             'value_name'=>$this->getAttributeName(),
00314         ))->setRenderer(Mage::getBlockSingleton('rule/editable'));
00315     }

getAttributeElementHtml (  ) 

Definition at line 317 of file Abstract.php.

00318     {
00319         return $this->getAttributeElement()->getHtml();
00320     }

getAttributeName (  ) 

Definition at line 119 of file Abstract.php.

00120     {
00121         return $this->getAttributeOption($this->getAttribute());
00122     }

getAttributeOptions (  ) 

Definition at line 105 of file Abstract.php.

00106     {
00107         return array();
00108     }

getAttributeSelectOptions (  ) 

Definition at line 110 of file Abstract.php.

00111     {
00112         $opt = array();
00113         foreach ($this->getAttributeOption() as $k=>$v) {
00114             $opt[] = array('value'=>$k, 'label'=>$v);
00115         }
00116         return $opt;
00117     }

getChooserContainerHtml (  ) 

Definition at line 402 of file Abstract.php.

00403     {
00404         $url = $this->getValueElementChooserUrl();
00405         $html = '';
00406         if ($url) {
00407             $html = '<div class="rule-chooser" url="'.$url.'"></div>';
00408         }
00409         return $html;
00410     }

getForm (  ) 

Definition at line 50 of file Abstract.php.

00051     {
00052         return $this->getRule()->getForm();
00053     }

getInputType (  ) 

This value will define which operators will be available for this condition.

Possible values are: string, numeric, date, select, multiselect, grid

Returns:
string

Reimplemented in Mage_CatalogRule_Model_Rule_Condition_Product, and Mage_SalesRule_Model_Rule_Condition_Address.

Definition at line 156 of file Abstract.php.

00157     {
00158         return 'string';
00159     }

getNewChildName (  ) 

Definition at line 264 of file Abstract.php.

00265     {
00266         return $this->getAddLinkHtml();
00267     }

getNewChildSelectOptions (  ) 

Reimplemented in Mage_CatalogRule_Model_Rule_Condition_Combine, Mage_SalesRule_Model_Rule_Condition_Combine, and Mage_SalesRule_Model_Rule_Condition_Product_Combine.

Definition at line 257 of file Abstract.php.

00258     {
00259         return array(
00260             array('value'=>'', 'label'=>Mage::helper('rule')->__('Please choose a condition to add...')),
00261         );
00262     }

getOperatorElement (  ) 

Definition at line 322 of file Abstract.php.

00323     {
00324         if (is_null($this->getOperator())) {
00325             foreach ($this->getOperatorOption() as $k=>$v) {
00326                 $this->setOperator($k);
00327                 break;
00328             }
00329         }
00330         return $this->getForm()->addField($this->getPrefix().'__'.$this->getId().'__operator', 'select', array(
00331             'name'=>'rule['.$this->getPrefix().']['.$this->getId().'][operator]',
00332             'values'=>$this->getOperatorSelectOptions(),
00333             'value'=>$this->getOperator(),
00334             'value_name'=>$this->getOperatorName(),
00335         ))->setRenderer(Mage::getBlockSingleton('rule/editable'));
00336     }

getOperatorElementHtml (  ) 

Definition at line 338 of file Abstract.php.

00339     {
00340         return $this->getOperatorElement()->getHtml();
00341     }

getOperatorName (  ) 

Definition at line 174 of file Abstract.php.

00175     {
00176         return $this->getOperatorOption($this->getOperator());
00177     }

getOperatorSelectOptions (  ) 

Definition at line 161 of file Abstract.php.

00162     {
00163         $type = $this->getInputType();
00164         $opt = array();
00165         $operatorByType = $this->getOperatorByInputType();
00166         foreach ($this->getOperatorOption() as $k=>$v) {
00167             if (!$operatorByType || in_array($k, $operatorByType[$type])) {
00168                 $opt[] = array('value'=>$k, 'label'=>$v);
00169             }
00170         }
00171         return $opt;
00172     }

getRemoveLinkHtml (  ) 

Definition at line 395 of file Abstract.php.

00396     {
00397         $src = Mage::getDesign()->getSkinUrl('images/rule_component_remove.gif');
00398         $html = ' <span class="rule-param"><a href="javascript:void(0)" class="rule-param-remove" title="'.Mage::helper('rule')->__('Remove').'"><img src="'.$src.'"  alt="" class="v-middle" /></a></span>';
00399         return $html;
00400     }

getTypeElement (  ) 

Definition at line 286 of file Abstract.php.

00287     {
00288         return $this->getForm()->addField($this->getPrefix().'__'.$this->getId().'__type', 'hidden', array(
00289             'name'=>'rule['.$this->getPrefix().']['.$this->getId().'][type]',
00290             'value'=>$this->getType(),
00291             'no_span'=>true,
00292             'class' => 'hidden',
00293         ));
00294     }

getTypeElementHtml (  ) 

Definition at line 296 of file Abstract.php.

00297     {
00298         return $this->getTypeElement()->getHtml();
00299     }

getValue (  ) 

Definition at line 211 of file Abstract.php.

00212     {
00213         if ($this->getInputType()=='date' && !$this->getIsValueParsed()) {
00214             // date format intentionally hard-coded
00215             $this->setValue(Mage::app()->getLocale()->date($this->getData('value'), Varien_Date::DATE_INTERNAL_FORMAT, null, false)
00216                 ->toString(Varien_Date::DATE_INTERNAL_FORMAT));
00217             $this->setIsValueParsed(true);
00218         }
00219         return $this->getData('value');
00220     }

getValueElement (  ) 

Reimplemented in Mage_CatalogRule_Model_Rule_Condition_Product.

Definition at line 362 of file Abstract.php.

00363     {
00364         $elementParams = array(
00365             'name'               => 'rule['.$this->getPrefix().']['.$this->getId().'][value]',
00366             'value'              => $this->getValue(),
00367             'values'             => $this->getValueSelectOptions(),
00368             'value_name'         => $this->getValueName(),
00369             'after_element_html' => $this->getValueAfterElementHtml(),
00370             'explicit_apply'     => $this->getExplicitApply(),
00371         );
00372         if ($this->getInputType()=='date') {
00373             // date format intentionally hard-coded
00374             $elementParams['input_format'] = Varien_Date::DATE_INTERNAL_FORMAT;
00375             $elementParams['format']       = Varien_Date::DATE_INTERNAL_FORMAT;
00376         }
00377         return $this->getForm()->addField($this->getPrefix().'__'.$this->getId().'__value',
00378             $this->getValueElementType(),
00379             $elementParams
00380         )->setRenderer($this->getValueElementRenderer());
00381     }

getValueElementHtml (  ) 

Definition at line 383 of file Abstract.php.

00384     {
00385         return $this->getValueElement()->getHtml();
00386     }

getValueElementRenderer (  ) 

Definition at line 354 of file Abstract.php.

00355     {
00356         if (strpos($this->getValueElementType(), '/')!==false) {
00357             return Mage::getBlockSingleton($this->getValueElementType());
00358         }
00359         return Mage::getBlockSingleton('rule/editable');
00360     }

getValueElementType (  ) 

Value element type will define renderer for condition value element

See also:
Varien_Data_Form_Element
Returns:
string

Reimplemented in Mage_CatalogRule_Model_Rule_Condition_Product, Mage_Rule_Model_Condition_Combine, Mage_SalesRule_Model_Rule_Condition_Address, and Mage_SalesRule_Model_Rule_Condition_Product_Subselect.

Definition at line 349 of file Abstract.php.

00350     {
00351         return 'text';
00352     }

getValueName (  ) 

Definition at line 222 of file Abstract.php.

00223     {
00224         $value = $this->getValue();
00225         if (is_null($value) || ''===$value) {
00226             return '...';
00227         }
00228 
00229         $options = $this->getValueSelectOptions();
00230         $valueArr = array();
00231         if (!empty($options)) {
00232             foreach ($options as $o) {
00233                 if (is_array($value)) {
00234                     if (in_array($o['value'], $value)) {
00235                         $valueArr[] = $o['label'];
00236                     }
00237                 } else {
00238                     if (is_array($o['value'])) {
00239                         foreach ($o['value'] as $v) {
00240                             if ($v['value']==$value) {
00241                                 return $v['label'];
00242                             }
00243                         }
00244                     }
00245                     if ($o['value']==$value) {
00246                         return $o['label'];
00247                     }
00248                 }
00249             }
00250         }
00251         if (!empty($valueArr)) {
00252             $value = implode(', ', $valueArr);
00253         }
00254         return $value;
00255     }

getValueParsed (  ) 

Definition at line 198 of file Abstract.php.

00199     {
00200         $value = $this->getData('value');
00201 
00202         $op = $this->getOperator();
00203         if (($op==='()' || $op==='!()') && is_string($value)) {
00204             $value = preg_split('#\s*[,;]\s*#', $value, null, PREG_SPLIT_NO_EMPTY);
00205             $this->setValue($value);
00206         }
00207 
00208         return $value;
00209     }

getValueSelectOptions (  ) 

Reimplemented in Mage_CatalogRule_Model_Rule_Condition_Product, and Mage_SalesRule_Model_Rule_Condition_Address.

Definition at line 189 of file Abstract.php.

00190     {
00191         $opt = array();
00192         foreach ($this->getValueOption() as $k=>$v) {
00193             $opt[] = array('value'=>$k, 'label'=>$v);
00194         }
00195         return $opt;
00196     }

loadArray ( arr  ) 

Reimplemented in Mage_CatalogRule_Model_Rule_Condition_Product.

Definition at line 76 of file Abstract.php.

00077     {
00078         $this->setType($arr['type']);
00079         $this->setAttribute(isset($arr['attribute']) ? $arr['attribute'] : false);
00080         $this->setOperator(isset($arr['operator']) ? $arr['operator'] : false);
00081         $this->setValue(isset($arr['value']) ? $arr['value'] : false);
00082         $this->setIsValueParsed(isset($arr['is_value_parsed']) ? $arr['is_value_parsed'] : false);
00083 
00084 //        $this->loadAttributeOptions();
00085 //        $this->loadOperatorOptions();
00086 //        $this->loadValueOptions();
00087         return $this;
00088     }

loadAttributeOptions (  ) 

loadOperatorOptions (  ) 

Reimplemented in Mage_SalesRule_Model_Rule_Condition_Product_Subselect.

Definition at line 124 of file Abstract.php.

00125     {
00126         $this->setOperatorOption(array(
00127             '=='  => Mage::helper('rule')->__('is'),
00128             '!='  => Mage::helper('rule')->__('is not'),
00129             '>='  => Mage::helper('rule')->__('equals or greater than'),
00130             '<='  => Mage::helper('rule')->__('equals or less than'),
00131             '>'   => Mage::helper('rule')->__('greater than'),
00132             '<'   => Mage::helper('rule')->__('less than'),
00133             '{}'  => Mage::helper('rule')->__('contains'),
00134             '!{}' => Mage::helper('rule')->__('does not contain'),
00135             '()'  => Mage::helper('rule')->__('is one of'),
00136             '!()' => Mage::helper('rule')->__('is not one of'),
00137         ));
00138         $this->setOperatorByInputType(array(
00139             'string' => array('==', '!=', '>=', '>', '<=', '<', '{}', '!{}', '()', '!()'),
00140             'numeric' => array('==', '!=', '>=', '>', '<=', '<', '()', '!()'),
00141             'date' => array('==', '>=', '<='),
00142             'select' => array('==', '!='),
00143             'multiselect' => array('==', '!=', '{}', '!{}'),
00144             'grid' => array('()', '!()'),
00145         ));
00146         return $this;
00147     }

loadValueOptions (  ) 

Reimplemented in Mage_Rule_Model_Condition_Combine, and Mage_SalesRule_Model_Rule_Condition_Product_Found.

Definition at line 179 of file Abstract.php.

00180     {
00181 //        $this->setValueOption(array(
00182 //            true  => Mage::helper('rule')->__('TRUE'),
00183 //            false => Mage::helper('rule')->__('FALSE'),
00184 //        ));
00185         $this->setValueOption(array());
00186         return $this;
00187     }

loadXml ( xml  ) 

Reimplemented in Mage_Rule_Model_Condition_Combine.

Definition at line 90 of file Abstract.php.

00091     {
00092         if (is_string($xml)) {
00093             $xml = simplexml_load_string($xml);
00094         }
00095         $arr = (array)$xml;
00096         $this->loadArray($arr);
00097         return $this;
00098     }

validate ( Varien_Object object  ) 

validateAttribute ( validatedValue  ) 

Validate product attrbute value for condition

Parameters:
mixed $validatedValue product attribute value
Returns:
bool

Condition attribute value

Comparison operator

Definition at line 430 of file Abstract.php.

00431     {
00432         if (is_object($validatedValue)) {
00433             return false;
00434         }
00435 
00436         /**
00437          * Condition attribute value
00438          */
00439         $value = $this->getValueParsed();
00440 
00441         /**
00442          * Comparison operator
00443          */
00444         $op = $this->getOperator();
00445 
00446         // if operator requires array and it is not, or on opposite, return false
00447         if ((($op=='()' || $op=='!()') && !is_array($value))
00448             || (!($op=='()' || $op=='!()' || $op=='!=' || $op=='==' || $op=='{}' || $op=='!{}') && is_array($value))) {
00449             return false;
00450         }
00451 
00452         $result = false;
00453 
00454         switch ($op) {
00455             case '==': case '!=':
00456                 if (is_array($value)) {
00457                     if (is_array($validatedValue)) {
00458                         $result = array_diff($validatedValue, $value);
00459                         $result = empty($result) && (sizeof($validatedValue) == sizeof($value));
00460                     } else {
00461                         return false;
00462                     }
00463                 } else {
00464                     if (is_array($validatedValue)) {
00465                         $result = in_array($value, $validatedValue);
00466                     } else {
00467                         $result = $validatedValue==$value;
00468                     }
00469                 }
00470                 break;
00471 
00472             case '<=': case '>':
00473                 if (is_array($validatedValue)) {
00474                     $result = false;
00475                 } else {
00476                     $result = $validatedValue<=$value;
00477                 }
00478                 break;
00479 
00480             case '>=': case '<':
00481                 if (is_array($validatedValue)) {
00482                     $result = false;
00483                 } else {
00484                     $result = $validatedValue>=$value;
00485                 }
00486                 break;
00487 
00488             case '{}': case '!{}':
00489                 if (is_array($value)) {
00490                     if (is_array($validatedValue)) {
00491                         $result = array_diff($value, $validatedValue);
00492                         $result = empty($result);
00493                     } else {
00494                         return false;
00495                     }
00496                 } else {
00497                     if (is_array($validatedValue)) {
00498                         $result = false;
00499                     } else {
00500                         $result = stripos((string)$validatedValue, (string)$value)!==false;
00501                     }
00502                 }
00503                 break;
00504 
00505             case '()': case '!()':
00506                 if (is_array($validatedValue)) {
00507                     $result = count(array_intersect($validatedValue, (array)$value))>0;
00508                 } else {
00509                     $result = in_array($validatedValue, (array)$value);
00510                 }
00511                 break;
00512         }
00513 
00514         if ('!='==$op || '>'==$op || '<'==$op || '!{}'==$op || '!()'==$op) {
00515             $result = !$result;
00516         }
00517 
00518         return $result;
00519     }


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