2013-07-03 09:33:55 +00:00

373 lines
7.1 KiB
PHP

<?php
/**
*
*
*/
class Metier_Sfr
{
/**
* Version of rules (for loading static files)
* @var double
*/
protected $version = '1.0';
/**
* Debug mode
* @var boolean
*/
protected $debug = false;
/**
* True, to use static file for set vars otherwise read in the database
* @var boolean
*/
protected $compile = true;
/**
* Feu vert
* @var int
*/
const VERT = 3;
/**
* Feu orange
* @var int
*/
const ORANGE = 2;
/**
* Feu rouge
* @var int
*/
const ROUGE = 1;
/**
* CAC = Entreprise du CAC
* @var int
*/
const CAC = 4;
/**
* GE = Grande Entreprise
* @var int
*/
const GE = 3;
/**
* Petites et Moyennes Entreprise
* @var int
*/
const PME = 2;
/**
* Très Petites Entreprise
* @var int
*/
const TPE = 1;
/**
* Constante valeur UNDEFINE
* @var null
*/
const UNDEFINE = null;
/**
* Liste des NAF Administration
* @var array
*/
protected $TabAdminNaf = null;
/**
* Liste des FJ Administration
* @var array
*/
protected $TabAdminFj = null;
protected $TabEtrangerNaf = null;
protected $TabEtrangerFj = null;
protected $TabNafSFR = null;
//Valeurs à remplir
protected $ValIsCAC = null;
protected $ValIsAdmin = null;
protected $ValIsEtranger = null;
protected $ValEffectif = null;
protected $ValNAF = null;
protected $ValFJ = null;
protected $ValRJ = null;
protected $ValLJ = null;
protected $ValSV = null;
protected $ValIndiscore = null;
protected $ValInseeActif = null;
protected $ValInseeAge = null;
protected $ValEntrepRecente = null;
protected $ValContratDate = null;
protected $ValIR = null;
protected $ValVOR = null;
protected $ValPO = null;
protected $ValComment = null;
//Rules
protected $RulesVORP = array();
protected $RulesVORD = array();
protected $RulesPO = array();
/**
*
* @param string $version
* @param string $compile
*/
public function __construct( $version = null, $compile = true )
{
$this->setVersion($version);
$this->setCompile($compile);
//Charger les Tabs
//Charger les Rules (dans l'ordre)
//Charger les paramètres
}
public function evaluate($siren)
{
//Identite
//Indiscore
//Rules
$ruleType = array( 'VORP' , 'VORD' , 'PO');
foreach ( $ruleType as $type ) {
$this->rules($type);
}
}
/**
* Execution des règles
* Si les conditions contenu dans la regle
*
*
* @param string $type
*/
protected function rules($type)
{
$rules = $this->{'Rules'.$type};
foreach ( $rules as $rule ) {
$return = $this->params($rule['params']);
// Continue always
if ( $rule['value'] == 'CONTINUE' ) {
continue;
}
//Continue
elseif ( $return === false ){
continue;
}
// Stop
elseif ( $rule['value'] == 'STOP' && $return === true ) {
break;
}
//Set Value
else {
$this->ValVOR = $this->paramValue($rule['value']);
break;
}
}
}
/**
* Traitement des conditions
* - Si la condition est FAUSSE
* => arrêt pour passer à la règle suivante
* - Si la condition est VRAI
* => passage à la condition suivante
* @param array $conditions
* - var : Nom de la variable
* - type : Type du test de la condition
* - value : Valeur à tester
* - define : "var" à définir avec la "value"
* @return boolean
*/
protected function params($conditions = array())
{
$test = false;
if ( count($conditions) > 0 ) {
foreach ( $conditions as $c ) {
$test = $this->paramEval($c['var'], $c['type'], $c['value']);
if ( null === $test ) {
// Oops ! Problem !
}
// Sortir des conditions
elseif ( $test === false ) {
break;
}
// Continuer les conditions suivantes
elseif ( $test === true ) {
if ( array_key_exists('define', $c) ) {
$this->paramDefine($c['define'], $c['define_value']);
}
}
}
}
return $test;
}
/**
* Transformation des variables
* @param string $val
* @return number|mixed|NULL
*/
protected function paramValue($val)
{
if ( is_numeric($val) ) {
return (float) $val;
}
if ( is_string($val) && defined('self::'.$val) ) {
return constant('self::'.$val);
}
if ( is_string($val) && is_array($this->{'Tab'.$val}) ) {
return $this->{'Tab'.$val};
}
return null;
}
/**
* Evaluation de la condition
* @param string $var
* @param string $type
* @param string $value
* @return boolean|NULL
*/
protected function paramEval($var, $type, $value)
{
$valueReal = $this->paramValue($value);
switch ($type) {
case 'MIN':
if ( $this->{'Val'.$var} > $valueReal ) {
return true;
}
return false;
break;
case 'MAX':
if ( $this->{'Val'.$var} < $valueReal ) {
return true;
}
return false;
break;
case 'EGAL':
if ( $this->{'Val'.$var} === $valueReal ) {
return true;
}
return false;
break;
case 'LIST':
if ( in_array($this->{'Val'.$var}, $valueReal) ) {
return true;
}
return false;
break;
}
return null;
}
/**
*
* @param string $name
* @param string $val
*/
protected function paramDefine($name, $val)
{
$value = null;
if ( is_numeric($val) ) {
$value = (int) $val;
}
if ( is_string($val) && defined('self::'.$val) ) {
$value = constant('self::'.$val);
}
$this->{'Val'.$name} = $value;
}
protected function comment(){}
/**
*
*/
protected function setTabs()
{
if ( $this->compile ) {
} else {
return $this->loadTabsFromDb();
}
}
/**
*
*/
protected function loadTabsFromDb(){}
/**
*
*/
protected function setRules()
{
if ( $this->compile ) {
$this->RulesVORp = include_once 'Metier/Sfr/RulesVORp-'.$this->version.'.php';
$this->RulesVORd = include_once 'Metier/Sfr/RulesVORd-'.$this->version.'.php';
} else {
$this->RulesVORp = $this->loadRulesFromDb('VORp');
$this->RulesVORd = $this->loadRulesFromDb('VORd');
}
}
protected function loadRulesFromDb($type = null)
{
}
protected function setCompile($compile = true)
{
$this->compile = $compile;
}
/**
* Define static file and version
* @param string $version
*/
protected function setVersion($version = null)
{
if ( null !== $version ) {
$this->version = $version;
}
}
}