This commit is contained in:
Michael RICOIS 2016-11-24 12:02:59 +01:00
parent 17f0a9a4d2
commit fa8593b78f
2 changed files with 48 additions and 27 deletions

View File

@ -2,28 +2,35 @@
class Metier_Sfr_Compile
{
/**
* Database adaptater
* @var Zend_Db_Adapter_Abstract
*/
protected $db;
/**
*
* Version
* @var string
*/
protected $version = null;
/**
* TXT to write in file
* @var string
*/
protected $compileTxt = "<?php\n";
public function __construct($db = null)
/**
* PDO Connection with Doctrine
* @var \Doctrine\DBAL\Connection
*/
protected $conn;
/**
* Bodacc
* @param \Doctrine\DBAL\Connection $conn
*/
public function __construct($conn = null)
{
if ( null === $db) {
$this->db = Zend_Db_Table_Abstract::getDefaultAdapter();
} else {
$this->db = $db;
}
if ($conn === null) {
$this->conn = Zend_Registry::get('doctrine');
}
else {
$this->conn = $conn;
}
}
public function setVersion($version)
@ -35,7 +42,8 @@ class Metier_Sfr_Compile
{
$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);
$stmt = $this->conn->executeQuery($sql);
$result = $stmt->fetchAll(\PDO::FETCH_OBJ);
return $result;
}
@ -43,14 +51,15 @@ class Metier_Sfr_Compile
{
$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);
$stmt = $this->conn->executeQuery($sql);
$result = $stmt->fetchAll(\PDO::FETCH_OBJ);
return $result;
}
public function construct($type)
{
$rules = $this->getRulesFromDb($type);
if ( count($rules) > 0 ) {
if (count($rules) > 0) {
$this->compileTxt.= "return array(\n";
$this->addRules($rules);
$this->compileTxt.= ");\n";
@ -63,7 +72,7 @@ class Metier_Sfr_Compile
public function addRules($rules)
{
foreach ( $rules as $i => $rule ) {
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";
@ -79,9 +88,9 @@ class Metier_Sfr_Compile
public function addParams($type, $codif)
{
$params = $this->getParamsFromDb($type, $codif);
if ( count($params) > 0 ) {
foreach ( $params as $i => $param ) {
if ( $param->define == '') {
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";
@ -89,5 +98,4 @@ class Metier_Sfr_Compile
}
}
}
}

View File

@ -38,9 +38,22 @@ if ($displayUsage) {
exit;
}
$c = new Zend_Config($application->getOptions());
$db = Zend_Db::factory($c->profil->db->metier);
Zend_Db_Table::setDefaultAdapter($db);
// Doctrine conn
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array(
'dbname' => $application->profil->db->metier->params->dbname,
'user' => $application->profil->db->metier->params->username,
'password' => $application->profil->db->metier->params->password,
'host' => $application->profil->db->metier->params->host,
'charset' => 'utf8',
'driver' => 'pdo_mysql',
);
try {
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
} catch (\Doctrine\DBAL\DBALException $e) {
exit;
}
$types = array('VORD', 'VORP', 'PO');
@ -51,7 +64,7 @@ if ( $opts->compile!='' && in_array($opts->compile, $types) ) {
if ( count($types) > 0 ) {
foreach ( $types as $type ) {
$ruleSfrM = new Metier_Sfr_Compile();
$ruleSfrM = new Metier_Sfr_Compile($conn);
$ruleSfrM->setVersion($opts->version);
$ruleSfrM->construct($type);
}