id = $id * 1;
$this->fetch_datas();
}
} // end of member function __construct
public function fetch_datas() {
if ($this->id) {
$query = "select * from contribution_area_areas where id_area = ".$this->id;
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
$result = pmb_mysql_fetch_object($result);
$this->id = $result->id_area;
$this->title = $result->area_title;
$this->comment = $result->area_comment;
$this->color = $result->area_color;
$this->order = $result->area_order;
$this->status = $result->area_status;
$this->opac_visibility = $result->area_opac_visibility;
$this->repo_template_authorities = $result->area_repo_template_authorities;
$this->repo_template_records = $result->area_repo_template_records;
$this->area_logo = $result->area_logo;
}
}
}
public function get_title() {
return $this->title;
}
public function set_title($title) {
$this->title = $title;
}
/**
* Parcours les enregistrement en base et renvoi la liste (ou un message indiquant que nous n'en avons pas)
*/
public static function get_list() {
global $msg;
global $contribution_area_list_tpl;
global $contribution_area_list_line_tpl;
global $contribution_area_add_button;
global $pmb_contribution_opac_edit_entity;
global $contribution_area_edit_entity;
$query = 'SELECT contribution_area_areas.*, contribution_area_status_gestion_libelle AS status_label
FROM contribution_area_areas
LEFT JOIN contribution_area_status ON area_status = contribution_area_status_id
ORDER BY area_order';
$result = pmb_mysql_query($query);
if (pmb_mysql_num_rows($result)) {
$list = '';
$pair = 'even';
while ( $area = pmb_mysql_fetch_object($result) ) {
if ($area->area_order == 0) {
SELF::update_order($area->id_area);
}
if ($pair == 'odd') {
$pair = 'even';
} else {
$pair = 'odd';
}
$list .= str_replace('!!odd_even!!', $pair, $contribution_area_list_line_tpl);
$list = str_replace('!!area_title!!', $area->area_title, $list);
$list = str_replace('!!area_color!!', $area->area_color, $list);
$list = str_replace('!!area_status!!', ($area->status_label ? $area->status_label : ""), $list);
$list = str_replace('!!disabled_default_area!!', ($pmb_contribution_opac_edit_entity ? $contribution_area_edit_entity : ""), $list);
if ($pmb_contribution_opac_edit_entity) {
//Bouton utilisé par défaut
$message = str_replace('%f', $area->area_title, $msg['contribution_area_confirm_default_area']);
$list = str_replace('!!confirm_msg_default!!', addslashes($message), $list);
if ($area->area_editing_entity) {
$list = str_replace('!!button_default_area!!', $msg['contribution_area_is_default_area'], $list);
$list = str_replace('!!disabled_default_area!!', 'disabled', $list);
} else {
$list = str_replace('!!button_default_area!!', $msg['contribution_area_default_area'], $list);
$list = str_replace('!!disabled_default_area!!', '', $list);
}
}
$list = str_replace('!!id!!', $area->id_area, $list);
}
$table = str_replace('!!list!!', $list, $contribution_area_list_tpl);
return $table . $contribution_area_add_button;
// return $table;
}
return '
' . $msg ['no_contribution_area_defined'] . '
' . $contribution_area_add_button;
}
public function get_form() {
global $contribution_area_form, $contribution_area_delete_button, $msg, $charset;
if ($this->id) {
$contribution_area_form = str_replace('!!delete!!', $contribution_area_delete_button, $contribution_area_form);
$contribution_area_form = str_replace('!!msg_title!!', $msg['contribution_area_form_edit'], $contribution_area_form);
$contribution_area_form = str_replace('!!id!!', $this->id, $contribution_area_form);
$contribution_area_form = str_replace('!!area_title!!', htmlentities($this->title, ENT_QUOTES, $charset), $contribution_area_form);
$contribution_area_form = str_replace('!!area_comment!!', htmlentities($this->comment, ENT_QUOTES, $charset), $contribution_area_form);
$contribution_area_form = str_replace('!!area_color!!', htmlentities($this->color, ENT_QUOTES, $charset), $contribution_area_form);
$contribution_area_form = str_replace('!!area_status!!', $this->get_status_options(), $contribution_area_form);
$contribution_area_form = str_replace('!!area_rights!!', $this->get_rights_form(), $contribution_area_form);
$contribution_area_form = str_replace('!!area_repo_template_authorities!!', htmlentities($this->repo_template_authorities, ENT_QUOTES, $charset), $contribution_area_form);
$contribution_area_form = str_replace('!!area_repo_template_records!!', htmlentities($this->repo_template_records, ENT_QUOTES, $charset), $contribution_area_form);
$contribution_area_form = str_replace('!!area_logo!!', htmlentities($this->area_logo, ENT_QUOTES, $charset), $contribution_area_form);
$contribution_area_form = str_replace('!!area_opac_visibility!!', ($this->opac_visibility ? 'checked' : '' ), $contribution_area_form);
} else {
$contribution_area_form = str_replace('!!delete!!', '', $contribution_area_form);
$contribution_area_form = str_replace('!!msg_title!!', $msg['contribution_area_form_create'], $contribution_area_form);
$contribution_area_form = str_replace('!!id!!', 0, $contribution_area_form);
$contribution_area_form = str_replace('!!area_title!!', '', $contribution_area_form);
$contribution_area_form = str_replace('!!area_comment!!', '', $contribution_area_form);
$contribution_area_form = str_replace('!!area_color!!', '', $contribution_area_form);
$contribution_area_form = str_replace('!!area_status!!', $this->get_status_options(), $contribution_area_form);
$contribution_area_form = str_replace('!!area_rights!!', $this->get_rights_form(), $contribution_area_form);
$contribution_area_form = str_replace('!!area_repo_template_authorities!!', '', $contribution_area_form);
$contribution_area_form = str_replace('!!area_repo_template_records!!', '', $contribution_area_form);
$contribution_area_form = str_replace('!!area_logo!!', htmlentities($this->area_logo, ENT_QUOTES, $charset), $contribution_area_form);
$contribution_area_form = str_replace('!!area_opac_visibility!!', 'checked', $contribution_area_form);
}
return $contribution_area_form;
}
public function get_definition_form(){
global $contribution_area_form_definition;
$form = str_replace("!!area_title!!", $this->title, $contribution_area_form_definition);
$form = str_replace ("!!available_entities_data!!",encoding_normalize::json_encode(contribution_area_forms_controller::get_store_data()),$form);
$form = str_replace ("!!graph_data_store!!",encoding_normalize::json_encode($this->get_graph_store_data()),$form);
$form = str_replace ("!!graph_shapes!!",encoding_normalize::json_encode($this->parse_graph_shapes()),$form);
$form = str_replace ("!!id!!",$this->id,$form);
print $form;
}
/**
* Non static (avoir pour des tests supp
* sur les éléments de scénarii)
*/
public function delete() {
//suppression des droits d'acces empr_contribution_area
$query_acces = "show tables like 'acces_res_4'";
$result_acces = pmb_mysql_query($query_acces);
if($result_acces && pmb_mysql_num_rows($result_acces)) {
$requete = "delete from acces_res_4 where res_num=".$this->id;
@pmb_mysql_query($requete);
}
$this->delete_in_store();
$query = 'delete from contribution_area_areas where id_area = "'.$this->id.'"';
return pmb_mysql_query($query);
}
private function delete_in_store() {
self::get_graphstore();
$succes = self::$graphstore->query('select * where {
?attachment .
?attachment '.$this->get_area_uri().' .
?attachment '.$this->get_area_uri().' .
?attachment ?scenario .
}');
if ($succes) {
$results = self::$graphstore->get_result();
foreach ($results as $row) {
$scenario_id = onto_common_uri::get_id($row->scenario);
contribution_area_scenario::delete($scenario_id);
}
$succes = self::$graphstore->query('delete {
?s ?p '.$this->get_area_uri().' .
}');
if (!$succes) {
var_dump(self::$graphstore->get_errors());
}
} else {
var_dump(self::$graphstore->get_errors());
}
}
public function save_from_form() {
global $area_title, $area_comment, $area_color, $area_status, $area_repo_template_authorities, $area_repo_template_records, $area_opac_visibility, $area_logo;
$this->title = stripslashes($area_title);
$this->comment = stripslashes($area_comment);
$this->color = stripslashes($area_color);
$this->status = stripslashes($area_status);
$this->repo_template_authorities = stripslashes($area_repo_template_authorities);
$this->repo_template_records = stripslashes($area_repo_template_records);
$this->opac_visibility = stripslashes($area_opac_visibility);
$this->area_logo = stripslashes($area_logo);
}
public function save() {
$query_clause = '';
if ($this->id) {
$update = true;
$query_statement = 'update ';
$query_clause = ' where id_area = '.$this->id;
} else {
$update = false;
$query_statement = 'insert into ';
$query = "SELECT MAX(area_order) FROM contribution_area_areas";
$result = pmb_mysql_query($query);
$max_order = pmb_mysql_result($result,0,0);
$this->order = $max_order + 1;
}
$query_statement .= ' contribution_area_areas set ';
$query_statement .= 'area_title = "'.addslashes($this->title).'", ';
$query_statement .= 'area_comment = "'.addslashes($this->comment).'", ';
$query_statement .= 'area_color = "'.addslashes($this->color).'", ';
$query_statement .= 'area_status = "'.addslashes($this->status).'", ';
$query_statement .= 'area_opac_visibility = "'.addslashes($this->opac_visibility).'", ';
$query_statement .= 'area_repo_template_authorities = "'.addslashes($this->repo_template_authorities).'", ';
$query_statement .= 'area_repo_template_records = "'.addslashes($this->repo_template_records).'", ';
$query_statement .= 'area_logo = "'.addslashes($this->area_logo).'", ';
$query_statement .= 'area_order = '.$this->order;
pmb_mysql_query($query_statement.$query_clause);
if(!$this->id){
$this->id = pmb_mysql_insert_id();
}
$this->save_rights($update);
}
protected function save_rights($update) {
global $gestion_acces_active, $gestion_acces_empr_contribution_area;
global $res_prf, $chk_rights, $prf_rad, $r_rad;
// traitement des droits acces user_contribution_area
if ($gestion_acces_active == 1 && $gestion_acces_empr_contribution_area == 1) {
$ac = new acces();
$dom_4 = $ac->setDomain(4);
if ($update) {
$dom_4->storeUserRights(1, $this->id, $res_prf, $chk_rights, $prf_rad, $r_rad);
} else {
$dom_4->storeUserRights(0, $this->id, $res_prf, $chk_rights, $prf_rad, $r_rad);
}
}
}
public static function get_ontology(){
global $base_path;
global $class_path;
if(!isset(self::$onto)){
$onto_store_config = array(
/* db */
'db_name' => DATA_BASE,
'db_user' => USER_NAME,
'db_pwd' => USER_PASS,
'db_host' => SQL_SERVER,
/* store */
'store_name' => 'ontodemo',
/* stop after 100 errors */
'max_errors' => 100,
'store_strip_mb_comp_str' => 0
);
$tab_namespaces = array(
"skos" => "http://www.w3.org/2004/02/skos/core#",
"dc" => "http://purl.org/dc/elements/1.1",
"dct" => "http://purl.org/dc/terms/",
"owl" => "http://www.w3.org/2002/07/owl#",
"rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs" => "http://www.w3.org/2000/01/rdf-schema#",
"xsd" => "http://www.w3.org/2001/XMLSchema#",
"pmb" => "http://www.pmbservices.fr/ontology#"
);
$onto_store = new onto_store_arc2_extended($onto_store_config);
$onto_store->set_namespaces($tab_namespaces);
//chargement de l'ontologie dans son store
$reset = $onto_store->load($class_path."/rdf/ontologies_pmb_entities.rdf", onto_parametres_perso::is_modified());
onto_parametres_perso::load_in_store($onto_store, $reset);
self::$onto = new onto_ontology($onto_store);
}
return self::$onto;
}
public function get_graph_store_data() {
$area_linked_entities = $this->get_attachment_detail($this->get_area_uri());
return $area_linked_entities;
}
private function get_attachment_detail($source_uri,$source_id=""){
$details = array();
$attachments = $this->get_attachment($source_uri);
for($i=0 ; $iget_infos($attachments[$i]->dest);
if(!empty($attachments[$i]->name)){
$node = array(
'type' => 'attachment',
'name' => $attachments[$i]->name,
'id' => $attachments[$i]->identifier,
'entityType' => $infos['entityType'],
'question' => !empty($attachments[$i]->question) ? $attachments[$i]->question : '',
'comment' => !empty($attachments[$i]->comment) ? $attachments[$i]->comment : '',
);
if($source_id){
$node['parent'] = $source_id;
}
if($attachments[$i]->property_pmb_name){
$node['propertyPmbName'] = $attachments[$i]->property_pmb_name;
}
$infos['parent'] = $attachments[$i]->identifier;
if (!in_array($node, $details)) {
$details[] = $node;
}
}else{
if($source_id){
$infos['parent'] = $source_id;
}
}
$details[] = $infos;
$details = array_merge($details, $this->get_attachment_detail('<'.$attachments[$i]->dest.'>', $infos['id']));
}
return $details;
}
private function get_attachment($source_uri){
$attachments = array();
self::get_graphstore();
$result = self::$graphstore->query('select * where {
?attachment rdf:type ca:Attachment .
?attachment ca:inArea '.$this->get_area_uri().' .
?attachment ca:attachmentSource '.$source_uri.' .
?attachment ca:attachmentDest ?dest .
?attachment ca:rights ?rights .
optional {
?attachment rdf:label ?name .
?attachment ca:identifier ?identifier .
?attachment pmb:name ?property_pmb_name .
optional {
?attachment pmb:question ?question .
?attachment pmb:comment ?comment
}
}
}');
if($result){
$attachments = self::$graphstore->get_result();
}
return $attachments;
}
public static function get_pmb_entities() {
$ontology = self::get_ontology();
$classes_array = $ontology->get_classes_uri();
$pmb_entities = array();
foreach($classes_array as $entity){
if (!isset($entity->flags) || !is_array($entity->flags) || !in_array("pmb_entity", $entity->flags)) {
continue;
}
$pmb_entities[$entity->pmb_name] = $entity->name;
}
return $pmb_entities;
}
private function get_infos($uri){
self::get_graphstore();
$infos = array();
$result = self::$graphstore->query('select * where {
<'.$uri.'> ?p ?o .
}');
if($result){
$results = self::$graphstore->get_result();
for($i=0 ; $ip){
case 'http://www.pmbservices.fr/ca/eltId' :
$infos['eltId'] = $results[$i]->o;
break;
case 'http://www.pmbservices.fr/ca/identifier' :
$infos['id'] = $results[$i]->o;
break;
case 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' :
switch($results[$i]->o){
case "http://www.pmbservices.fr/ca/Form" :
$infos['type'] = 'form';
break;
case "http://www.pmbservices.fr/ca/Scenario" :
$infos['type'] = 'scenario';
break;
default :
$infos['type'] = $results[$i]->o;
break;
}
break;
case 'http://www.w3.org/1999/02/22-rdf-syntax-ns#label' :
$infos['name'] = $results[$i]->o;
break;
case 'http://www.pmbservices.fr/ontology#entity' :
$infos['entityType'] = $results[$i]->o;
break;
case 'http://www.pmbservices.fr/ontology#startScenario' :
$infos['startScenario'] = $results[$i]->o;
break;
case 'http://www.pmbservices.fr/ontology#displayed' :
$infos['displayed'] = $results[$i]->o;
break;
case 'http://www.pmbservices.fr/ontology#parentScenario' :
$infos['parentScenario'] = $results[$i]->o;
break;
case 'http://www.pmbservices.fr/ontology#question' :
$infos['question'] = $results[$i]->o;
break;
case 'http://www.pmbservices.fr/ontology#comment' :
$infos['comment'] = $results[$i]->o;
break;
case 'http://www.pmbservices.fr/ontology#status' :
$infos['status'] = $results[$i]->o;
break;
case 'http://www.pmbservices.fr/ontology#response' :
$infos['response'] = $results[$i]->o;
break;
case 'http://www.pmbservices.fr/ontology#equation' :
$infos['equation'] = $results[$i]->o;
break;
}
}
}
return $infos;
}
public function save_graph($data, $current_scenario = 0){
self::get_graphstore();
if ($this->id) {
// On commence par supprimer ce qui existe
$query = "
select ?suj where {
?suj ca:inArea id.">
}
";
$result = self::$graphstore->query($query);
if(!$result){
var_dump("Errors : ".self::$graphstore->get_errors());
} else {
$rows = self::$graphstore->get_result();
foreach ($rows as $row) {
$query = "delete {
<".$row->suj."> ?prop ?obj
}";
$result_delete = self::$graphstore->query($query);
if(!$result_delete){
var_dump("Errors : ".self::$graphstore->get_errors());
}
}
}
}
//on encadre les float avec des guillemets sinon json_decode arrondit l'id
$data = encoding_normalize::utf8_normalize(preg_replace('/:\s*(\-?\d+(\.\d+)?([e|E][\-|\+]\d+)?)/', ': "$1"', stripslashes($data)));
$data = json_decode($data);
$graph_data = $this->prepare_data($data);
$query = 'delete {';
for($i=0 ; $iquery($query);
if(!$result){
var_dump(self::$graphstore->get_errors());
}
$query = 'insert into {';
for($i=0 ; $iquery($query);
if(!$result){
var_dump(self::$graphstore->get_errors());
}
contribution_area_scenario::save_current_scenario($current_scenario);
}
private function prepare_data($data){
$tree = $this->init_tree($data);
$assertions = array();
for($i=0 ; $igetAttachmentAssertions($this->getObjectUri($tree[$i],true),$this->get_area_uri() , $tree[$i]));
// les infos de l'élément
$assertions = array_merge($assertions,$this->get_node_assertions($tree[$i]));
//la suite...
if(!empty($tree[$i]->children)){
$assertions = array_merge($assertions, $this->getChildrenAssertions($this->getObjectUri($tree[$i]),$tree[$i]->children));
}
}
return $assertions;
}
private function getChildrenAssertions($source,$children){
$assertions = array();
for($i=0 ; $iget_node_assertions($children[$i]));
//attachment
if($children[$i]->type == 'attachment'){
for($j=0 ; $jchildren) ; $j++){
$assertions = array_merge($assertions, $this->getAttachmentAssertions($this->getObjectUri($children[$i],true),$source , $children[$i]->children[$j]));
}
$assertions = array_merge($assertions, $this->getChildrenAssertions($this->getObjectUri($children[$i]),$children[$i]->children));
}else{
if(!isset($children[$i]->parentType) || ($children[$i]->parentType != 'attachment')){
$assertions = array_merge($assertions,$this->getAttachmentAssertions($this->getObjectUri($children[$i],true),$source , $children[$i]));
}
if(count($children[$i]->children)){
$assertions = array_merge($assertions, $this->getChildrenAssertions($this->getObjectUri($children[$i]),$children[$i]->children));
}
}
}
return $assertions;
}
private function getAttachmentAssertions($attachment_uri,$source,$dest){
$assertions = array();
$assertions[] =array(
'subject' => $attachment_uri,
'predicat' => 'rdf:type',
'value' => 'ca:Attachment'
);
$assertions[] =array(
'subject' => $attachment_uri,
'predicat' => 'ca:inArea',
'value' => $this->get_area_uri()
);
$assertions[] =array(
'subject' => $attachment_uri,
'predicat' => 'ca:attachmentSource',
'value' => $source
);
$assertions[] =array(
'subject' => $attachment_uri,
'predicat' => 'ca:attachmentDest',
'value' => $this->getObjectUri($dest)
);
$assertions[] =array(
'subject' => $attachment_uri,
'predicat' => 'ca:rights',
'value' => '"TBD"'
);
return $assertions;
}
private function getObjectUri($object,$attachment=false){
$uri = $this->get_uri($object,$attachment);
return '<'.$uri.'>';
}
private function get_uri($object,$attachment=false){
if($attachment){
$uri = "http://www.pmbservices.fr/ca/Attachement#!!id!!";
$id = $object->type.$object->id;
if($object->type == 'attachment'){
$id = $object->entityType.$object->id;
}
return str_replace('!!id!!',$id,$uri);
}
switch($object->type) {
case 'form' :
$uri = "http://www.pmbservices.fr/ca/Form#!!id!!";
break;
case 'attachment' :
$uri = "http://www.pmbservices.fr/ca/Attachement#!!id!!";
break;
case 'startScenario' :
case 'scenario' :
$uri = "http://www.pmbservices.fr/ca/Scenario#!!id!!";
break;
}
return str_replace('!!id!!',$object->id,$uri);
}
private function init_tree($data){
$tree = array();
//reformatage..
for($i=0 ; $itype) && $data[$i]->type == "scenario" && !isset($data[$i]->parentScenario)){
$node = $data[$i];
if (!empty($data[$i]->startScenario) && $this->has_children($data[$i]->id, $data)) {
$node->children = $this->get_children($data[$i]->id, $data);
}
$tree[]=$node;
}
}
return $tree;
}
private function get_children($parent, $data) {
$children = array();
for($i=0 ; $iparent) && $parent == $data[$i]->parent){
$child = $data[$i];
$child->children = array();
if ($this->has_children($child->id, $data)) {
$child->children = $this->get_children($child->id, $data);
}
$children[] = $data[$i];
}
}
return $children;
}
private function has_children($parent, $data) {
for($i=0 ; $i < count($data); $i++) {
if(isset($data[$i]->parent) && $parent == $data[$i]->parent){
return true;
}
}
return false;
}
private function get_node_assertions($data){
$scenario_uri = "";
$attachment_uri = "";
$form_uri = "";
$assertions = array();
// ON GERE LE GENERAL
switch($data->type){
case 'scenario':
//l'URI du noeud en cours
$node_uri = str_replace('!!id!!',$data->id,$scenario_uri);
//le type de noeud
$node_type = 'ca:Scenario';
if(isset($data->equation)){
$assertions[] = array(
'subject' => $node_uri,
'predicat' => 'pmb:equation',
'value' => '"'.addslashes($data->equation).'"'
);
}
break;
case 'form':
//l'URI du noeud en cours
$node_uri = str_replace('!!id!!',$data->id,$form_uri);
//le type de noeud
$node_type = 'ca:Form';
//Propriétés communes é tous
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'ca:eltId',
'value' => '"'.addslashes($data->eltId).'"'
);
break;
case 'attachment':
//l'URI du noeud en cours
$node_uri = str_replace('!!id!!',$data->entityType.$data->id,$attachment_uri);
//le type de noeud
$node_type = 'ca:Attachment';
// //Propriétés communes é tous
// $assertions[] =array(
// 'subject' => $node_uri,
// 'predicat' => 'ca:eltId',
// 'value' => '"'.addslashes($data->eltId).'"'
// );
}
//Propriétés communes à tous
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'ca:identifier',
'value' => '"'.addslashes($data->id).'"'
);
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'rdf:type',
'value' => $node_type
);
if(isset($data->name)){
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'rdf:label',
'value' => '"'.addslashes($data->name).'"'
);
}
if(isset($data->propertyPmbName)){
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'pmb:name',
'value' => '"'.addslashes($data->propertyPmbName).'"'
);
}
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'pmb:entity',
'value' => '"'.addslashes($data->entityType).'"'
);
if(isset($data->startScenario)){
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'pmb:startScenario',
'value' => '"'.addslashes($data->startScenario).'"'
);
}
if(isset($data->displayed)){
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'pmb:displayed',
'value' => '"'.addslashes($data->displayed).'"'
);
}
if(isset($data->parentScenario)){
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'pmb:parentScenario',
'value' => '"'.addslashes($data->parentScenario).'"'
);
}
if(isset($data->question)){
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'pmb:question',
'value' => '"'.addslashes($data->question).'"'
);
}
if(isset($data->response)){
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'pmb:response',
'value' => '"'.addslashes($data->response).'"'
);
}
if(isset($data->comment)){
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'pmb:comment',
'value' => '"'.addslashes($data->comment).'"'
);
}
if(isset($data->status)){
$assertions[] =array(
'subject' => $node_uri,
'predicat' => 'pmb:status',
'value' => '"'.addslashes($data->status).'"'
);
}
return $assertions;
}
public function get_area_uri(){
return "id.">";
}
public static function get_graphstore(){
if(!isset(self::$graphstore)){
$store_config = array(
/* db */
'db_name' => DATA_BASE,
'db_user' => USER_NAME,
'db_pwd' => USER_PASS,
'db_host' => SQL_SERVER,
/* store */
'store_name' => 'contribution_area_graphstore',
/* stop after 100 errors */
'max_errors' => 100,
'store_strip_mb_comp_str' => 0
);
$tab_namespaces = array(
"dc" => "http://purl.org/dc/elements/1.1",
"dct" => "http://purl.org/dc/terms/",
"owl" => "http://www.w3.org/2002/07/owl#",
"rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs" => "http://www.w3.org/2000/01/rdf-schema#",
"xsd" => "http://www.w3.org/2001/XMLSchema#",
"pmb" => "http://www.pmbservices.fr/ontology#",
"ca" => "http://www.pmbservices.fr/ca/"
);
self::$graphstore = new onto_store_arc2($store_config);
self::$graphstore->set_namespaces($tab_namespaces);
}
return self::$graphstore;
}
public static function search_datatype_ui_class_name($property, $onto_pmb_name, $onto_name='common'){
$pmb_datatype = substr($property->pmb_datatype,strpos($property->pmb_datatype,"#")+1);
$suffix = "_ui";
$pmb_datatype_suffix = $suffix;
if ($restriction && $restriction->get_max() != -1) {
$pmb_datatype_suffix = "_card_ui";
}
$class_name = "onto_".$onto_name."_".$onto_pmb_name."_datatype_".$property->pmb_name.$suffix;
if(!class_exists($class_name)){
$class_name = "onto_".$onto_name."_datatype_".$property->pmb_name.$suffix;
if(!class_exists($class_name)){
$class_name = "onto_".$onto_name."_".$onto_pmb_name."_datatype_".$pmb_datatype.$pmb_datatype_suffix;
if(!class_exists($class_name)){
$class_name = "onto_".$onto_name."_datatype_".$pmb_datatype.$pmb_datatype_suffix;
if(!class_exists($class_name)){
if($onto_name == "common"){
$class_name = "onto_common_datatype_small_text_ui";
if(class_exists("onto_".$onto_name."_datatype_".$pmb_datatype."_ui")){
$class_name = "onto_".$onto_name."_datatype_".$pmb_datatype."_ui";
}
}else{
$class_name = self::search_datatype_ui_class_name($property, $onto_pmb_name);
}
}
}
}
}
return $class_name;
}
protected function get_all_scenarios($area_linked_entities) {
$scenarios = array();
$result = self::$graphstore->query('SELECT * WHERE {
?scenario rdf:type ca:Scenario .
}');
if($result){
$scenarios = self::$graphstore->get_result();
}
$infos = array();
for ($i=0; $i < count($scenarios); $i++) {
$scenario = $this->get_infos($scenarios[$i]->scenario);
if (isset($scenario['displayed']) && $scenario['displayed']) {
$scenario['displayed'] = false;
}
$infos[] = $scenario;
}
foreach ($infos as $info) {
if (!isset($area_linked_entities[$info['id']])) {
$area_linked_entities[$info['id']] = $info;
}
}
return array_values($area_linked_entities);
}
public function get_status_options() {
global $charset;
$query = "SELECT contribution_area_status_id, contribution_area_status_gestion_libelle FROM contribution_area_status";
$result = pmb_mysql_query($query);
$options = "";
if (pmb_mysql_num_rows($result)) {
while ($row = pmb_mysql_fetch_object($result)) {
$options .= "";
}
}
return $options;
}
public function get_rights_form() {
global $msg, $charset;
global $gestion_acces_active, $gestion_acces_empr_contribution_area;
global $gestion_acces_empr_contribution_area_def;
if ($gestion_acces_active != 1)
return '';
$ac = new acces();
$form = '';
$c_form = "
" . htmlentities($msg['dom_cur_prf'], ENT_QUOTES, $charset) . "
" . htmlentities($msg['dom_cur_rights'], ENT_QUOTES, $charset) . "
";
if ($gestion_acces_empr_contribution_area == 1) {
$r_form = $c_form;
$dom_4 = $ac->setDomain(4);
$r_form = str_replace('', htmlentities($dom_4->getComment('long_name'), ENT_QUOTES, $charset), $r_form);
if ($this->id) {
// profil ressource
$def_prf = $dom_4->getComment('res_prf_def_lib');
$res_prf = $dom_4->getResourceProfile($this->id);
$q = $dom_4->loadUsedResourceProfiles();
// Recuperation droits generiques utilisateur
$user_rights = $dom_4->getDomainRights(0, $res_prf);
if ($user_rights & 2) {
$p_sel = gen_liste($q, 'prf_id', 'prf_name', 'res_prf[4]', '', $res_prf, '0', $def_prf, '0', $def_prf);
$p_rad = "";
$r_form = str_replace('', $p_rad, $r_form);
} else {
$r_form = str_replace('', htmlentities($dom_4->getResourceProfileName($res_prf), ENT_QUOTES, $charset), $r_form);
}
// droits/profils utilisateurs
if ($user_rights & 1) {
$r_rad = "";
$r_form = str_replace('', $r_rad, $r_form);
}
// recuperation profils utilisateurs
$t_u = array();
$t_u[0] = $dom_4->getComment('user_prf_def_lib'); // niveau par defaut
$qu = $dom_4->loadUsedUserProfiles();
$ru = pmb_mysql_query($qu);
if (pmb_mysql_num_rows($ru)) {
while ( ($row = pmb_mysql_fetch_object($ru)) ) {
$t_u[$row->prf_id] = $row->prf_name;
}
}
// recuperation des controles dependants de l'utilisateur
$t_ctl = $dom_4->getControls(0);
// recuperation des droits
$t_rights = $dom_4->getResourceRights($this->id);
if (count($t_u)) {
$h_tab = "";
foreach ( $t_u as $k => $v ) {
$h_tab .= "" . htmlentities($v, ENT_QUOTES, $charset) . " | ";
}
$h_tab .= "
";
$c_tab = '';
foreach ( $t_u as $k => $v ) {
$c_tab .= " | ";
$t_rows = "";
foreach ( $t_ctl as $k2 => $v2 ) {
$t_rows .= "
|
";
} else {
$t_rows .= "/>
|
";
}
}
$c_tab = str_replace('', $t_rows, $c_tab);
}
$c_tab .= "";
}
$h_tab = str_replace('', $c_tab, $h_tab);
;
$r_form = str_replace('', $h_tab, $r_form);
} else {
$r_form = str_replace('', htmlentities($msg['dom_prf_unknown'], ENT_QUOTES, $charset), $r_form);
$r_form = str_replace('', htmlentities($msg['dom_rights_unknown'], ENT_QUOTES, $charset), $r_form);
}
$form .= $r_form;
}
return $form;
}
public function get_id() {
return $this->id;
}
public function get_color() {
return $this->color;
}
public function get_computed_form() {
global $contribution_area_computed_form;
$form = $contribution_area_computed_form;
$search = array(
"!!area_title!!",
"!!available_entities_data!!",
"!!environment_fields!!",
"!!empr_fields!!",
"!!graph_data_store!!",
"!!computed_fields!!",
"!!id!!"
);
$replace = array(
$this->title,
encoding_normalize::json_encode(encoding_normalize::utf8_decode(contribution_area_forms_controller::get_store_data())),
encoding_normalize::json_encode(computed_field::get_environment_fields()),
encoding_normalize::json_encode(computed_field::get_empr_fields()),
encoding_normalize::json_encode($this->get_graph_store_data()),
encoding_normalize::json_encode(computed_field::get_area_computed_fields_num($this->id)),
$this->id
);
$form = str_replace($search, $replace, $form);
return $form;
}
protected function parse_graph_shapes() {
global $include_path;
$objects = array();
if (file_exists($include_path.'/contribution_area/scenario_graph_subst.xml')) {
$parsed = simplexml_load_file($include_path.'/contribution_area/scenario_graph_subst.xml');
}
if (file_exists($include_path.'/contribution_area/scenario_graph.xml')) {
$parsed = simplexml_load_file($include_path.'/contribution_area/scenario_graph.xml');
}
if (!$parsed) {
return $objects;
}
foreach ($parsed->children() as $child) {
$objects[] = $child;
}
return $objects;
}
public function up_order() {
$query_min_order = 'SELECT MIN(area_order) FROM contribution_area_areas';
$select_min_order = pmb_mysql_query($query_min_order);
$min_order = pmb_mysql_result($select_min_order,0,0);
$query_contribution_current = "SELECT * FROM contribution_area_areas WHERE id_area = $this->id";
$select_contribution_current = pmb_mysql_query($query_contribution_current);
$contribution_current = pmb_mysql_fetch_assoc($select_contribution_current);
$order = $this->order - 1;
if ($order < $min_order) {
$order = $min_order;
}
$query_contribution_old = "SELECT * FROM contribution_area_areas WHERE area_order = $order";
$select_contribution_old = pmb_mysql_query($query_contribution_old);
$contribution_old = pmb_mysql_fetch_assoc($select_contribution_old);
$query_update_contribution_current = "UPDATE contribution_area_areas SET area_order = $order WHERE id_area =".$contribution_current['id_area'] ;
pmb_mysql_query($query_update_contribution_current);
$query_update_contribution_old = "UPDATE contribution_area_areas SET area_order = $this->order WHERE id_area =".$contribution_old['id_area'] ;
pmb_mysql_query($query_update_contribution_old);
}
public function down_order() {
$query_max_order = 'SELECT MAX(area_order) FROM contribution_area_areas';
$select_max_order = pmb_mysql_query($query_max_order);
$max_order = pmb_mysql_result($select_max_order,0,0);
$query_contribution_current = "SELECT * FROM contribution_area_areas WHERE id_area = $this->id";
$select_contribution_current = pmb_mysql_query($query_contribution_current);
$contribution_current = pmb_mysql_fetch_assoc($select_contribution_current);
$order = $this->order + 1;
if ($order > $max_order) {
$order = $max_order;
}
$query_contribution_old = "SELECT * FROM contribution_area_areas WHERE area_order = $order";
$select_contribution_old = pmb_mysql_query($query_contribution_old);
$contribution_old = pmb_mysql_fetch_assoc($select_contribution_old);
$query_update_contribution_current = "UPDATE contribution_area_areas SET area_order = $order WHERE id_area =".$contribution_current['id_area'] ;
pmb_mysql_query($query_update_contribution_current);
$query_update_contribution_old = "UPDATE contribution_area_areas SET area_order = $this->order WHERE id_area =".$contribution_old['id_area'] ;
pmb_mysql_query($query_update_contribution_old);
}
public static function update_order($id_area) {
$query_max_order = 'SELECT MAX(area_order) FROM contribution_area_areas';
$select_max_order = pmb_mysql_query($query_max_order);
$max_order = pmb_mysql_result($select_max_order,0,0) + 1;
$query = "UPDATE contribution_area_areas SET area_order = $max_order WHERE id_area =".$id_area ;
pmb_mysql_query($query);
}
public static function get_list_ajax() {
$area_list = array();
$query = 'SELECT contribution_area_areas.*, contribution_area_status_gestion_libelle AS status_label
FROM contribution_area_areas
LEFT JOIN contribution_area_status ON area_status = contribution_area_status_id
ORDER BY area_order';
$result = pmb_mysql_query($query);
if (pmb_mysql_num_rows($result)) {
while ( $area = pmb_mysql_fetch_object($result) ) {
$area_list[$area->id_area] = $area;
}
$area_list["total"] = count($area_list);
}
return $area_list;
}
public function duplicate_scenario_to_area() {
global $data, $duplicate_forms, $source_area_id;
self::get_graphstore();
//on encadre les float avec des guillemets sinon json_decode arrondit l'id
$data = json_decode(preg_replace('/:\s*(\-?\d+(\.\d+)?([e|E][\-|\+]\d+)?)/', ': "$1"', stripslashes($data)));
// On modifie les "identifier"
$link = array();
foreach ($data as $node) {
$new_id = $this->generate_identifier();
if ('form' === $node->type && "true" === $duplicate_forms) {
$form = new contribution_area_form($node->entityType, $node->eltId);
$form->generate_duplication_form();
$node->eltId = $form->get_id();
$node->name = $form->get_name();
$node->comment = $form->get_comment();
}
computed_field::duplicate_all_computed_field($source_area_id, $node->id, $new_id, $this->id);
$link[$node->id] = $new_id;
$node->id = $new_id;
}
// Modifie les id des parent avec les nouveaux "identifier"
foreach ($data as $node) {
if (!empty($node->parent) && $link[$node->parent]) {
$node->parent = $link[$node->parent];
}
}
$graph_data = $this->prepare_data($data);
$query = 'insert into {';
for ($i=0 ; $i < count($graph_data) ; $i++) {
$query.= '
'.$graph_data[$i]['subject'].' '.$graph_data[$i]['predicat'].' '.$graph_data[$i]['value'].' .';
}
$query.='
}';
$succes = self::$graphstore->query($query);
if(!$succes){
var_dump(self::$graphstore->get_errors());
}
}
public function generate_identifier() {
self::get_graphstore();
$temp_identifier = "0.".round(microtime(true)*10000);
$query = "select * where {
?uri ?identifier .
filter regex(?identifier, '".$temp_identifier."')
}";
$succes = self::$graphstore->query($query);
if($succes){
$results = self::$graphstore->get_result();
if(!empty($results)){
$temp_identifier = $this->generate_identifier();
}else{
return $temp_identifier;
}
}else{
var_dump("Errors : ".self::$graphstore->get_errors());
}
}
public function set_area_default()
{
if (empty($this->id)) {
return false;
}
$query = "UPDATE contribution_area_areas SET area_editing_entity = 0 WHERE area_editing_entity = 1";
pmb_mysql_query($query);
$query = "UPDATE contribution_area_areas SET area_editing_entity = 1 WHERE id_area = '" . $this->id . "'";
pmb_mysql_query($query);
}
public function get_acces_editing_entity() {
global $msg;
return [
0 => $msg['contribution_area_is_default_area_not_use'],
1 => $msg['contribution_area_is_default_area']
];
}
public function get_normalized_item(){
$retour = array(
"id" => $this->id,
"title" => $this->title,
"comment" => (!empty($this->comment) ? $this->comment : ''),
"color" => (!empty($this->color) ? $this->color : ''),
"order" => (!empty($this->order) ? $this->order : ''),
"status" => (!empty($this->status) ? $this->status : ''),
"opac_visibility" => $this->opac_visibility,
"repo_template_authorities" => (!empty($this->repo_template_authorities) ? $this->repo_template_authorities : ''),
"repo_template_records" => (!empty($this->repo_template_records) ? $this->repo_template_records : ''),
"area_logo" => (!empty($this->area_logo) ? $this->area_logo : '')
);
return $retour;
}
} // end of contribution_area