db = Zend_Db_Table_Abstract::getDefaultAdapter(); } else { $this->db = $db; } } public function setVersion($version) { $this->version = $version; } public function getRulesFromDb($type) { $version = str_replace('.','',$this->version); $sql = "SELECT * FROM jo.sfr_rules_".$version." AS r WHERE r.type='".$type."' ORDER BY r.ordre"; $result = $this->db->fetchAll($sql, array(), Zend_Db::FETCH_OBJ); return $result; } public function getParamsFromDb($type, $codif) { $version = str_replace('.','',$this->version); $sql = "SELECT * FROM jo.sfr_params_".$version." AS p WHERE p.type='".$type."' AND p.codif='".$codif."' ORDER BY p.ordre"; $result = $this->db->fetchAll($sql, array(), Zend_Db::FETCH_OBJ); return $result; } public function construct($type) { $rules = $this->getRulesFromDb($type); if ( count($rules) > 0 ) { $this->compileTxt.= "return array(\n"; $this->addRules($rules); $this->compileTxt.= ");\n"; } $filename = realpath(__DIR__).'/Rules'.ucfirst(strtolower($type)).'-'.$this->version.'.php'; file_put_contents($filename, $this->compileTxt); } public function addRules($rules) { foreach ( $rules as $i => $rule ) { $this->compileTxt.= "\t".$i." => array(\n"; $this->compileTxt.= "\t\t'name' => '".$rule->label."',\n"; $this->compileTxt.= "\t\t'value' => '".$rule->value."',\n"; $this->compileTxt.= "\t\t'po' => ".$rule->po.",\n"; $this->compileTxt.= "\t\t'comment' => \"".$rule->comment."\",\n"; $this->compileTxt.= "\t\t'params' => array(\n"; $this->addParams($rule->type, $rule->codif); $this->compileTxt.= "\t\t),\n"; $this->compileTxt.= "\t),\n"; } } public function addParams($type, $codif) { $params = $this->getParamsFromDb($type, $codif); if ( count($params) > 0 ) { foreach ( $params as $i => $param ) { if ( $param->define == '') { $this->compileTxt.= "\t\t\t".$i." => array( 'var' => '".$param->var."', 'type' => '".$param->cond."', 'value' => '".$param->value."'),\n"; } else { $this->compileTxt.= "\t\t\t".$i." => array( 'var' => '".$param->var."', 'type' => '".$param->cond."', 'value' => '".$param->value."', 'define' => array( 'var' => '".$param->define."', 'value' => '".$param->define_value."')),\n"; } } } } }