[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+*********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 *************************************************************************************/ 10 11 class VTEventCondition{ 12 function __construct($expr){ 13 if($expr!=''){ 14 $parser = $this->getParser($expr); 15 $this->expr = $parser->statement(); 16 }else{ 17 $this->expr = null; 18 } 19 } 20 21 22 function test($obj){ 23 $this->data = $obj; 24 if($this->expr==null){ 25 return true; 26 }else{ 27 return $this->evaluate($this->expr); 28 } 29 } 30 31 private function getParser($expr){ 32 $ass = new ANTLRStringStream($expr); 33 $lex = new VTEventConditionParserLexer($ass); 34 $cts = new CommonTokenStream($lex); 35 $tap = new VTEventConditionParserParser($cts); 36 return $tap; 37 } 38 39 40 private function evaluate($expr){ 41 if(is_array($expr)){ 42 $oper = $expr[0]; 43 if($oper=='.'){ 44 $out = $this->data; 45 $syms = array_slice($expr, 1); 46 foreach($syms as $sym){ 47 $out = $this->get($out, $sym->name); 48 } 49 return $out; 50 }else{ 51 $evaled = array_map(array($this, 'evaluate'), array_slice($expr, 1)); 52 switch($oper){ 53 case "in": 54 return in_array($evaled[0], $evaled[1]); 55 case "==": 56 return $evaled[0] == $evaled[1]; 57 case "list": 58 return $evaled; 59 default: 60 return false; 61 } 62 } 63 }else{ 64 if($expr instanceof VTEventConditionSymbol){ 65 return $this->get($this->data, $expr->name); 66 }else{ 67 return $expr; 68 } 69 } 70 } 71 72 private function get($obj, $field){ 73 if(is_array($obj)){ 74 return $obj[$field]; 75 }else{ 76 $func = "get".ucwords($field); 77 return $obj->$func(); 78 } 79 80 } 81 } 82 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |