Source for file class.sdi.php
Documentation is available at class.sdi.php
* @package linea21.modules
* @author linea21 <info@linea21.com>
* @license http://opensource.org/licenses/gpl-3.0.html
* SDI (Sustainable Development Indicators) Management
// nom des tables utilisées dans l'objet.
// variables utilisées pour caractéristiques principales d'un IDD
// variables utilisées pour critères d'évaluation d'un ID
// variables utilisées pour organisme fournisseur d'un IDD
// variables utilisées pour réglementation d'un IDD
// variables utilisées pour valeur d'un IDD
public function __call($method, $arguments)
$event = $this->dispatcher->notifyUntil(new sfEvent($this, 'sdi.extensible_function', array(
'arguments' => $arguments
if (!$event->isProcessed())
throw new Exception(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
return $event->getReturnValue();
* sdi::CheckDataIntegrity_value()
* Vérification d'une valeur d'un indicateur
* @param array $table contient les composants d'un indicateur
* @return boolean si vrai renvoie true sinon message d'erreurs (string)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_datacheck_value', array('data' => $table)), $table);
$table = $r->getReturnValue();
$notgoodvalue = strtolower(_t('dashboard','object_notgoodvalue'));
// test values only if max and min values are known
if(!is_null($result[0]['sdii_max_value']) && !is_null($result[0]['sdii_min_value'])) {
// test only if threshold field is not blank
if($result[0]['sdii_max_value'] < $result[0]['sdii_min_value']) {
if ($table[2] > $result[0]['sdii_min_value'] || $table[2] < $result[0]['sdii_max_value']) return ucfirst(_t('dashboard','threshold_value')) . ' : '. $notgoodvalue;
if($table[2] < $result[0]['sdii_min_value'] || $table[2] > $result[0]['sdii_max_value']) return ucfirst(_t('dashboard','threshold_value')) . ' : '. $notgoodvalue;
if($result[0]['sdii_max_value'] < $result[0]['sdii_min_value']) {
if ($table[0] > $result[0]['sdii_min_value'] || $table[0] < $result[0]['sdii_max_value']) return ucfirst(_t('dashboard','value')) . ' : '. $notgoodvalue;
if($table[0] < $result[0]['sdii_min_value'] || $table[0] > $result[0]['sdii_max_value']) return ucfirst(_t('dashboard','value')) . ' : '. $notgoodvalue;
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_datacheck_value', array('data' => $table)));
* sdi::CheckDataIntegrity_info()
* Vérification des données générales d'un indicateur
* @param array $table contient les composants d'un indicateur
* @return boolean si vrai renvoie true sinon message d'erreurs (string)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_datacheck_info', array('data' => $table)), $table);
$table = $r->getReturnValue();
$notname = _t('sdi','object_notname');
$notdescription = _t('sdi','object_notdescription');
$nottheme = _t('sdi','object_nottheme');
//$notrange = _t('sdi','object_notrange');
$notunit = _t('sdi','object_notunit');
$notmax_value = _t('sdi','object_notmax_value');
$notmin_value = _t('sdi','object_notmin_value');
$notthreshold_value = _t('sdi','object_notthreshold_value');
$notfrequency = _t('sdi','object_notfrequency');
if (strlen($table[0]) < 2) return $notname;
if (strlen($table[1]) < 2) return $notdescription;
if ($table[3] <= 0 || !is_numeric($table[3])) return $nottheme;
$table[7]= trim($table[7]);
if (empty($table[7])) return $notunit;
if (!empty($table[8]) && !is_numeric($table[8])) return $notmax_value;
if (!empty($table[9]) && !is_numeric($table[9])) return $notmin_value;
if (!empty($table[10]) && !is_numeric($table[10])) return $notthreshold_value;
if (!is_numeric($table[11])) return $notfrequency;
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_datacheck_info', array('data' => $table)));
* sdi::CheckDataIntegrity_eval()
* Vérification des données d'évaluation d'un indicateur
* @param array $table contient les composants évaluation d'un indicateur
* @return boolean si vrai renvoie true sinon message d'erreurs (string)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_datacheck_eval', array('data' => $table)), $table);
$table = $r->getReturnValue();
$note_scale_compare = _t('sdi','object_note_scale_compare');
$note_fiability = _t('sdi','object_note_fiability');
$note_accessibility = _t('sdi','object_note_accessibility');
$note_lisibility = _t('sdi','object_note_lisibility');
$note_relevance = _t('sdi','object_note_relevance');
$note_global_performance = _t('sdi','object_note_global_performance');
if (!is_numeric($table[13])) return $note_scale_compare;
if (!is_numeric($table[14])) return $note_fiability;
if (!is_numeric($table[15])) return $note_accessibility;
if (!is_numeric($table[16])) return $note_lisibility;
if (!is_numeric($table[17])) return $note_relevance;
if (!is_numeric($table[18])) return $note_global_performance;
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_datacheck_eval', array('data' => $table)));
* sdi::CheckDataIntegrity_provider()
* Vérification des données d'un fournisseur d'un indicateur
* @param array $table contient les composants évaluation d'un indicateur
* @return boolean si vrai renvoie true sinon message d'erreurs (string)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_datacheck_provider', array('data' => $table)), $table);
$table = $r->getReturnValue();
$notp_name = _t('sdi','object_notp_name');
$notp_address = _t('sdi','object_notp_address');
$notp_phone = _t('sdi','object_notp_phone');
$notp_fax = _t('sdi','object_notp_fax');
$notp_mail = _t('sdi','object_notp_mail');
if (strlen($table[19]) < 2) return $notp_name;
if (strlen($table[23]) < 2) return $notp_address;
if (trim($table[24]) != '' && !is_numeric($table[24])) return $notp_phone;
if (trim($table[25]) != '' && !is_numeric($table[25])) return $notp_fax;
$testmail = $this->_checkEmailValidity($table[26]);
if ($testmail=== false) return $notp_mail;
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_datacheck_provider', array('data' => $table)));
* sdi::CheckDataIntegrity_reglementation()
* Vérification des données de réglementation d'un indicateur
* @param array $table contient les composants réglementation d'un indicateur
* @return boolean si vrai renvoie true sinon message d'erreurs (string)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_datacheck_reglementation', array('data' => $table)), $table);
$table = $r->getReturnValue();
$notr_title = _t('sdi','object_notr_title');
$notr_body = _t('sdi','object_notr_body');
if (strlen($table[27]) < 2) return $notr_title;
if (strlen($table[28]) < 2) return $notr_body;
if(CHECK_LINK== true && !empty($table[29])) {
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_datacheck_reglementation', array('data' => $table)));
* sdi::_checkEmailValidity()
* @param string $email contient les composants d'un mail
* @return boolean si vrai renvoie true sinon message d'erreurs (string)
function _checkEmailValidity($email)
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.check_email_validity', array('data' => $table)));
* resources::CheckOnlineFile()
* vérifie l'existence d'un fichier en ligne
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.check_online_file', array('path' => $path)));
$file_pt = @fopen($path, 'r');
if (!$file_pt) return false;
* Ajout d'un nouveau fournisseur d'un IDD
* @param object $sql_object
* @return integer $last_id
function _AddProvider($sql_object)
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.add_provider'));
$q = "INSERT INTO " . $this->TDB_SDI_PROVIDER . " (sdip_name, sdip_service, sdip_description, sdip_incharge, sdip_address, sdip_phone, sdip_fax, sdip_email, sdip_date_crea) VALUES ('','','', '', '', '', '', '',NOW());";
$last_id = $sql_object->DBInsert ($q, 1);
* Ajout de critères d'évaluation d'un IDD
* @param object $sql_object
* @return integer $last_id
function _AddEvaluation ($sql_object)
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.add_evaluation'));
$q = "INSERT INTO " . $this->TDB_SDI_EVAL . " (sdie_scale_compare, sdie_fiability, sdie_accessibility, sdie_lisibility, sdie_relevance, sdie_global_performance, sdie_date_crea)VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT,NOW());";
$last_id = $sql_object->DBInsert ($q, 1);
* Ajout d'une réglementation d'un IDD
* @param object $sql_object
* @return integer $last_id
function _AddRules($sql_object)
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.add_rules'));
$q = "INSERT INTO " . $this->TDB_SDI_RULES . " (sdir_title, sdir_body, sdir_referer_uri, sdir_mask_uri, sdir_date_crea) VALUES ('', '', '', '', NOW());";
$last_id = $sql_object->DBInsert ($q, 1);
* @param array $table_sdi_info contient les infos detaillees d'un IDD
* @param object $sql_object
* @return integer $last_id
function AddSdi($table_sdi_info, $sql_object)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_add_indicator', array('data' => $table_sdi_info)), $table_sdi_info);
$table_sdi_info = $r->getReturnValue();
$table_sdi_info= $sql_object->DBescape($table_sdi_info);
$this->I_THEME = $table_sdi_info[3];
$this->I_RANGE = $table_sdi_info[4];
if($table_sdi_info[8]== '') {
if($table_sdi_info[9]== '') {
if($table_sdi_info[10]== '') {
$this->I_PROVIDER = $this->_AddProvider($sql_object);
$this->I_TYPE = $table_sdi_info[15];
$q = "INSERT INTO " . $this->TDB_SDI_INFO . " (sdii_type, sdii_dashboard_viz, sdii_detail_viz, sdii_name, sdii_description, sdii_comment, sdii_theme, sdii_range, sdii_goal,
sdii_consulting, sdii_to_dashboard, sdii_unit, sdii_max_value, sdii_min_value, sdii_threshold_value, sdii_threshold_relative, sdii_frequency, sdii_provider, sdii_evaluation,
$result = $sql_object->DBInsert ($q, 1);
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_add_indicator', array('data' => $table_sdi_info, 'id' => $result)));
* @param array $table_sdi_value contient les composants d'une valeur d'un IDD
* @param object $sql_object
* @return integer $last_id
function AddValue($table_sdi_value, $sql_object)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_add_value', array('data' => $table_sdi_value)), $table_sdi_value);
$table_sdi_value = $r->getReturnValue();
$table_sdi_value= $sql_object->DBescape($table_sdi_value);
$this->V_VALUE = $table_sdi_value[0];
if(!empty($table_sdi_value[2])) {
$this->V_SCALE = $table_sdi_value[3];
$q = "INSERT INTO " . $this->TDB_SDI_VALUE . " (sdiv_value, sdiv_sdi_info, sdiv_threshold, sdiv_comment, sdiv_comment_display, sdiv_scale, sdiv_date_published, sdiv_statut, sdiv_date_crea)
$last_id = $sql_object->DBInsert ($q, 1);
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_add_value', array('data' => $table_sdi_value, 'id' => $last_id)));
* @param int $ID identifiant de l'IDD
* @param object $sql_object
* @param array $table_sdi_info contient les composants d'un IDD
function ModifySdi($ID, $table_sdi_info, $sql_object)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_modify_indicator', array('data' => $table_sdi_info)), $table_sdi_info);
$table_sdi_info = $r->getReturnValue();
$table_sdi_info= $sql_object->DBescape($table_sdi_info);
$this->I_THEME = $table_sdi_info[3];
$this->I_RANGE = $table_sdi_info[4];
if($table_sdi_info[8]== '') {
if($table_sdi_info[9]== '') {
if($table_sdi_info[10]== '') {
$this->I_TYPE = $table_sdi_info[15];
. $this->I_TYPE . "', sdii_dashboard_viz='"
. $this->I_NAME . "', sdii_description='"
. $this->I_STATUT . "', sdii_last_modify= NOW()
WHERE sdii_id=" . $this->I_ID . ";";
$result = $sql_object->DBQuery ($q);
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_modify_indicator', array('data' => $table_sdi_info, 'id' => $ID)));
* récupération des clés d'un ID
* @param int $id_id identifiant de l'IDD
* @param object $sql_object
* @return array $table_key
function _GetKeysSdi($sdi_id, $sql_object)
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.get_indicator_keys', array('id' => $sdi_id)));
$q = "SELECT sdii_provider, sdii_evaluation, sdii_reglementation
WHERE sdii_id=" . $this->I_ID . ";";
$result = $sql_object->DBSelect($q);
* modification des paramètres d'un IDD en fonction de son sdii_id
* @param int $ID identifiant de l'IDD
* @param array $tableparam contient les composants d'un IDD
* @param string $param paramètre passé :
* @param object $sql_object
function ModifyParam($ID, $tableparam, $param, $sql_object)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_modify_params', array('data' => $tableparam, 'id' => $ID, 'element' => $param)), $table_sdi_info);
$table_sdi_info = $r->getReturnValue();
$data = $this->_GetKeysSdi($ID, $sql_object);
$id_e = $data[0]['sdii_evaluation'];
$result = $this->_ModifyEvaluation($id_e, $tableparam, $sql_object);
$data = $this->_GetKeysSdi($ID, $sql_object);
$id_p = $data[0]['sdii_provider'];
$result = $this->_ModifyProvider($id_p, $tableparam, $sql_object);
$data = $this->_GetKeysSdi($ID, $sql_object);
$id_r = $data[0]['sdii_reglementation'];
$result = $this->_ModifyRules($id_r, $tableparam, $sql_object);
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_modify_params', array('data' => $tableparam, 'id' => $ID, 'element' => $param)));
* @param int $id identifiant de l'IDD a supprimer
* @param object $sql_object
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.delete_indicator', array('id' => $ID)));
$result = $this->StateSdi($ID, $state, $sql_object);
$q = "UPDATE " . $this->TDB_SDI_VALUE . " SET sdiv_statut='" . $state . "' WHERE sdiv_sdi_info=" . $ID . ";";
$result2 = $sql_object->DBQuery ($q);
* sdi::_ModifyEvaluation()
* modification d'une évaluation IDD
* @param int $ID identifiant de l'évaluation
* @param object $sql_object
* @param array $table_sdi_eval contient les composants d'un IDD
function _ModifyEvaluation($ID, $table_sdi_eval, $sql_object)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_modify_evaluation', array('data' => $table_sdi_eval, 'id' => $ID)), $table_sdi_eval);
$table_sdi_eval = $r->getReturnValue();
$table_sdi_eval= $sql_object->DBescape($table_sdi_eval);
$q = "UPDATE " . $this->TDB_SDI_EVAL . " SET sdie_scale_compare='" . $this->E_SCALE . "', sdie_fiability='"
WHERE sdie_id=" . $this->E_ID . ";";
$result = $sql_object->DBQuery ($q);
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_modify_evaluation', array('data' => $table_sdi_eval, 'id' => $ID)));
* modification d'un fournisseur IDD
* @param int $ID identifiant du fournisseur
* @param object $sql_object
* @param array $table_sdi_provider contient les composants d'un fournisseur
function _ModifyProvider ($ID, $table_sdi_provider, $sql_object)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_modify_provider', array('data' => $table_sdi_provider, 'id' => $ID)), $table_sdi_provider);
$table_sdi_provider = $r->getReturnValue();
$table_sdi_provider= $sql_object->DBescape($table_sdi_provider);
. $this->P_PHONE . "', sdip_fax='" . $this->P_FAX . "', sdip_email='"
. $this->P_EMAIL . "', sdip_last_modify = NOW()
WHERE sdip_id='" . $this->P_ID . "';";
$result = $sql_object->DBQuery ($q);
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_modify_provider', array('data' => $table_sdi_provider, 'id' => $ID)));
* modification d'une réglementation
* @param int $ID identifiant d'une réglementation
* @param object $sql_object
* @param array $table_sdi_rules contient les composants d'une réglementation
function _ModifyRules ($ID, $table_sdi_rules, $sql_object)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_modify_rules', array('data' => $table_sdi_rules, 'id' => $ID)), $table_sdi_rules);
$table_sdi_rules = $r->getReturnValue();
$table_sdi_rules= $sql_object->DBescape($table_sdi_rules);
. $this->R_MASK_URI . "', sdir_last_modify = NOW()
WHERE sdir_id='" . $this->R_ID . "';";
$result = $sql_object->DBQuery ($q);
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_modify_rules', array('data' => $table_sdi_rules, 'id' => $ID)));
* modification d'une valeur
* @param int $ID identifiant d'une valeur
* @param object $sql_object
* @param array $table_sdi_value contient les composants d'une valeur
function ModifyValue ($ID, $table_sdi_value, $sql_object)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'indicator.before_modify_value', array('data' => $table_sdi_value, 'id' => $ID)), $table_sdi_value);
$table_sdi_value = $r->getReturnValue();
$table_sdi_value= $sql_object->DBescape($table_sdi_value);
$this->V_VALUE = $table_sdi_value[0];
if(!empty($table_sdi_value[2])) {
$this->V_SCALE = $table_sdi_value[3];
WHERE sdiv_id=" . $this->V_ID . ";";
$result = $sql_object->DBQuery ($q);
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.after_modify_value', array('data' => $table_sdi_value, 'id' => $ID)));
* modification simple du rang d'un IDD
* @param int $ID identifiant de l'IDD
* @param object $sql_object
* @param int $range contient la valeur du rang à modifier
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.change_range', array('id' => $ID, 'range' => $range)));
$q = "UPDATE " . $this->TDB_SDI_INFO . " SET sdii_range=" . $this->I_RANGE . ", sdii_last_modify= NOW() WHERE sdii_id='" . $this->I_ID . "';";
$result = $sql_object->DBQuery ($q);
* modification simple du statut d'un IDD
* @param int $ID identifiant de l'IDD
* @param object $sql_object
* @param string $state contient la valeur du statut à modifier
function StateSdi ($ID, $state, $sql_object)
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.change_indicator_state', array('id' => $ID, 'state' => $state)));
$q = "UPDATE " . $this->TDB_SDI_INFO . " SET sdii_statut='" . $state . "' WHERE sdii_id=" . $this->ID . ";";
$result = $sql_object->DBQuery ($q);
* modification simple du statut d'une valeur d'un IDD
* @param int $id identifiant de l'IDD
* @param object $sql_object
* @param string $state contient la valeur du statut à modifier
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.change_value_state', array('id' => $ID, 'state' => $state)));
$q = "UPDATE " . $this->TDB_SDI_VALUE . " SET sdiv_statut='" . $state . "' WHERE sdiv_id=" . $this->ID . ";";
$result = $sql_object->DBQuery ($q);
* suppression d'une valeur d'un IDD
* @param int $id identifiant de la valeur a supprimer
* @param object $sql_object
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.delete_value', array('id' => $ID)));
$result = $this->StateValue($ID, $state, $sql_object);
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'indicator.get_info', array('id' => $id)));
if(SQL== 'mysql') $datefunction= "DATE_FORMAT";
if(SQL== 'pgsql') $datefunction= "to_char";
$q = "SELECT II.sdii_id, II.sdii_name, II.sdii_description, II.sdii_comment, T.theme_name, II.sdii_theme,
II.sdii_range, II.sdii_goal, II.sdii_consulting, II.sdii_unit, II.sdii_max_value, II.sdii_min_value,
II.sdii_threshold_value, II.sdii_threshold_relative, II.sdii_frequency, II.sdii_provider, IP.sdip_name, II.sdii_evaluation, II.sdii_reglementation,
" . $datefunction . "(II.sdii_date_crea, '" . toStringSqlDate() . "' ) AS date_c, II.sdii_statut
FROM " . $this->TDB_SDI_INFO . " AS II LEFT OUTER JOIN " . $this->TDB_THEME . " as T on II.sdii_theme=T.theme_id
LEFT OUTER JOIN " . $this->TDB_SDI_PROVIDER . " as IP on II.sdii_provider=IP.sdip_id";
$q .= " WHERE II.sdii_id=" . $id . ";";
$result = $sql_object->DBSelect ($q);
* sdi::getScalesThresholds()
* return an associative array with threshold value for
* @param int $id Indicator ID
* @param $default_threshold
* @param object $sql_object
foreach($scales as $scale) {
if(isset ($r[0]['sdiv_value']) && !is_null($r[0]['sdiv_threshold'])) {
$a[$scale->scale_id] = $r[0]['sdiv_threshold'];
_debug('key : '. $scale->scale_id . ' - value : '. $r[0]['sdiv_threshold']);
$a[$scale->scale_id] = $default_threshold;
_debug('key : '. $scale->scale_id . ' - value : '. $default_threshold. '(default)');
|