Doctrine
This commit is contained in:
parent
17f0a9a4d2
commit
fa8593b78f
@ -2,28 +2,35 @@
|
|||||||
class Metier_Sfr_Compile
|
class Metier_Sfr_Compile
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Database adaptater
|
* Version
|
||||||
* @var Zend_Db_Adapter_Abstract
|
|
||||||
*/
|
|
||||||
protected $db;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $version = null;
|
protected $version = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TXT to write in file
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $compileTxt = "<?php\n";
|
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) {
|
if ($conn === null) {
|
||||||
$this->db = Zend_Db_Table_Abstract::getDefaultAdapter();
|
$this->conn = Zend_Registry::get('doctrine');
|
||||||
} else {
|
}
|
||||||
$this->db = $db;
|
else {
|
||||||
}
|
$this->conn = $conn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setVersion($version)
|
public function setVersion($version)
|
||||||
@ -35,7 +42,8 @@ class Metier_Sfr_Compile
|
|||||||
{
|
{
|
||||||
$version = str_replace('.','',$this->version);
|
$version = str_replace('.','',$this->version);
|
||||||
$sql = "SELECT * FROM jo.sfr_rules_".$version." AS r WHERE r.type='".$type."' ORDER BY r.ordre";
|
$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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,14 +51,15 @@ class Metier_Sfr_Compile
|
|||||||
{
|
{
|
||||||
$version = str_replace('.','',$this->version);
|
$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";
|
$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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function construct($type)
|
public function construct($type)
|
||||||
{
|
{
|
||||||
$rules = $this->getRulesFromDb($type);
|
$rules = $this->getRulesFromDb($type);
|
||||||
if ( count($rules) > 0 ) {
|
if (count($rules) > 0) {
|
||||||
$this->compileTxt.= "return array(\n";
|
$this->compileTxt.= "return array(\n";
|
||||||
$this->addRules($rules);
|
$this->addRules($rules);
|
||||||
$this->compileTxt.= ");\n";
|
$this->compileTxt.= ");\n";
|
||||||
@ -63,7 +72,7 @@ class Metier_Sfr_Compile
|
|||||||
|
|
||||||
public function addRules($rules)
|
public function addRules($rules)
|
||||||
{
|
{
|
||||||
foreach ( $rules as $i => $rule ) {
|
foreach ($rules as $i => $rule) {
|
||||||
$this->compileTxt.= "\t".$i." => array(\n";
|
$this->compileTxt.= "\t".$i." => array(\n";
|
||||||
$this->compileTxt.= "\t\t'name' => '".$rule->label."',\n";
|
$this->compileTxt.= "\t\t'name' => '".$rule->label."',\n";
|
||||||
$this->compileTxt.= "\t\t'value' => '".$rule->value."',\n";
|
$this->compileTxt.= "\t\t'value' => '".$rule->value."',\n";
|
||||||
@ -79,9 +88,9 @@ class Metier_Sfr_Compile
|
|||||||
public function addParams($type, $codif)
|
public function addParams($type, $codif)
|
||||||
{
|
{
|
||||||
$params = $this->getParamsFromDb($type, $codif);
|
$params = $this->getParamsFromDb($type, $codif);
|
||||||
if ( count($params) > 0 ) {
|
if (count($params) > 0) {
|
||||||
foreach ( $params as $i => $param ) {
|
foreach ($params as $i => $param) {
|
||||||
if ( $param->define == '') {
|
if ($param->define == '') {
|
||||||
$this->compileTxt.= "\t\t\t".$i." => array( 'var' => '".$param->var."', 'type' => '".$param->cond."', 'value' => '".$param->value."'),\n";
|
$this->compileTxt.= "\t\t\t".$i." => array( 'var' => '".$param->var."', 'type' => '".$param->cond."', 'value' => '".$param->value."'),\n";
|
||||||
} else {
|
} 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";
|
$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
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -38,9 +38,22 @@ if ($displayUsage) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$c = new Zend_Config($application->getOptions());
|
// Doctrine conn
|
||||||
$db = Zend_Db::factory($c->profil->db->metier);
|
$config = new \Doctrine\DBAL\Configuration();
|
||||||
Zend_Db_Table::setDefaultAdapter($db);
|
$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');
|
$types = array('VORD', 'VORP', 'PO');
|
||||||
|
|
||||||
@ -51,7 +64,7 @@ if ( $opts->compile!='' && in_array($opts->compile, $types) ) {
|
|||||||
if ( count($types) > 0 ) {
|
if ( count($types) > 0 ) {
|
||||||
|
|
||||||
foreach ( $types as $type ) {
|
foreach ( $types as $type ) {
|
||||||
$ruleSfrM = new Metier_Sfr_Compile();
|
$ruleSfrM = new Metier_Sfr_Compile($conn);
|
||||||
$ruleSfrM->setVersion($opts->version);
|
$ruleSfrM->setVersion($opts->version);
|
||||||
$ruleSfrM->construct($type);
|
$ruleSfrM->construct($type);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user