name = $entity->get_display_name_for_area();
$store_data[] = $entity;
foreach (self::$entity_forms[$entity->uri] as $form) {
foreach ($form["properties"] as $property) {
$store_data[] = $property;
}
unset($form["properties"]);
$store_data[] = $form;
}
}
$store_data = array_merge($store_data,self::$contribution_status);
self::$store_data = $store_data;
return self::$store_data;
}
public static function fetch_data(){
if(!self::$initialized){
self::$entities = array();
$ontology = contribution_area::get_ontology();
$classes_array = $ontology->get_classes_uri();
foreach($classes_array as $entity){
if (isset($entity->flags) && (is_array($entity->flags) && in_array('pmb_entity', $entity->flags))) {
$entity->type = "entity";
$entity->id = self::get_identifier();
self::$entities[] = $entity;
$classes_properties = $ontology->get_class_properties($entity->uri);
foreach ($classes_properties as $property_uri) {
$property = $ontology->get_property($entity->uri, $property_uri);
self::$classes_properties[$entity->pmb_name][$property->pmb_name] = $ontology->get_property($entity->uri, $property_uri);
}
self::$entity_forms[$entity->uri] = array();
self::get_entity_forms(self::$entity_forms[$entity->uri], $entity);
}
}
self::$initialized = true;
}
}
public static function get_datastore() {
if (! isset ( self::$datastore )) {
$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_datastore',
/* 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::$datastore = new onto_store_arc2_extended ( $store_config );
self::$datastore->set_namespaces ( $tab_namespaces );
}
return self::$datastore;
}
public static function delete_uri($uri) {
// On supprime tous les triplets correspondant ŕ cette uri
$query_delete = "delete {
<".$uri."> ?prop ?obj
}";
self::get_datastore ()->query($query_delete);
$query_delete = "delete {
?suj ?prop <".$uri.">
}";
self::get_datastore ()->query($query_delete);
}
public static function get_identifier(){
self::$identifier++;
return self::$identifier;
}
public static function get_entity_forms(&$forms_array, $entity){
$query = 'select id_form, form_title, form_comment, form_parameters from contribution_area_forms where form_type = "'.$entity->pmb_name.'"';
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
while($row = pmb_mysql_fetch_object($result)){
$forms_array[] = array(
'type' => "form",
'form_id' => $row->id_form,
'id' => self::get_identifier(),
'parent_type' => $entity->pmb_name,
'name' => $row->form_title,
'comment' => $row->form_comment,
'parent' => $entity->id,
'pmb_name' => $entity->pmb_name,
);
$form_parameters = json_decode($row->form_parameters, true);
$properties = array();
if(is_array($form_parameters)){
foreach($form_parameters as $prop => $pValues){
//on regarde s'il s'agit d'un toogle
$properties[] = array(
'type' => "property",
'form_id' => $row->id_form,
'id' => self::get_identifier(),
'parent_type' => $entity->pmb_name,
'name' => $pValues['label'],
'flag' => (!empty(self::$classes_properties[$entity->pmb_name][$prop]->flags[0]) ? self::$classes_properties[$entity->pmb_name][$prop]->flags[0] : ""),
'pmb_name' => (!empty(self::$classes_properties[$entity->pmb_name][$prop]->pmb_name) ? self::$classes_properties[$entity->pmb_name][$prop]->pmb_name : "")
);
}
}
$forms_array[count($forms_array)-1]["properties"] = $properties;
}
}
return $forms_array;
}
public static function display_forms_list(){
global $contribution_area_entity_line;
global $contribution_area_form_line;
global $contribution_area_form_table;
global $msg;
global $charset;
self::fetch_data();
$form_list = '
';
$i = 0;
foreach (self::$entities as $entity) {
$forms = "";
if (!is_array($entity)) {
$form_line = str_replace('!!entity_id!!', $i.$entity->id, $contribution_area_entity_line);
$form_line = str_replace('!!entity_name!!', $entity->get_display_name(), $form_line);
$form_line = str_replace('!!entity_type!!', $entity->pmb_name, $form_line);
$form_line = str_replace('!!forms_table!!', (count(self::$entity_forms[$entity->uri]) ? $contribution_area_form_table : "") , $form_line);
$j = 0;
foreach (self::$entity_forms[$entity->uri] as $form) {
$j++;
$forms .= $contribution_area_form_line;
if ($j % 2) {
$forms = str_replace('!!odd_even!!', "odd", $forms);
} else {
$forms = str_replace('!!odd_even!!', "even", $forms);
}
$forms = str_replace('!!form_name!!', htmlentities($form['name'], ENT_QUOTES, $charset), $forms);
$forms = str_replace('!!form_id!!', $form['form_id'], $forms);
$forms = str_replace('!!form_type!!', $entity->pmb_name, $forms);
//On va vérifier si le formulaire est dans un scénario auquel cas on disable la suppression avec un autre message
$contribution_form = new contribution_area_form($entity->pmb_name, $form['form_id']);
$has_linked_scenario = $contribution_form->get_scenario_linked()['count'];
//Desactivation des boutons supprimer pour les formulaires comportant des brouillons (message prioritaire sur le message d'utilisatiuon du formulaire dans un scénario)
if (contribution_area_form::has_draft_contribution_from_id($form['form_id'])){
$forms = str_replace('!!disabled!!', 'disabled', $forms);
$forms = str_replace('!!disabled_message!!', $msg['contribution_has_draft_hover'], $forms);
}
else if ($has_linked_scenario) {
$forms = str_replace('!!disabled!!', 'disabled', $forms);
$forms = str_replace('!!disabled_message!!', $msg['contribution_has_scenario_hover'], $forms);
} else {
$forms = str_replace('!!disabled!!', '', $forms);
$forms = str_replace('!!disabled_message!!', '', $forms);
}
unset($contribution_form);
}
$form_line = str_replace('!!forms_number!!', '('.$j.')', $form_line);
$form_line = str_replace('!!forms_tab!!', $forms, $form_line);
$form_list.= $form_line;
$i++;
}
}
$form_list .= "
";
return $form_list;
}
public static function get_forms_by_entity($entity){
}
public static function get_contribution_status() {
if (!count(self::$contribution_status)) {
$query = "SELECT contribution_area_status_id AS id, contribution_area_status_gestion_libelle AS name, contribution_area_status_available_for as available_for FROM contribution_area_status";
$result = pmb_mysql_query($query);
if (pmb_mysql_num_rows($result)) {
while ($row = pmb_mysql_fetch_assoc($result)) {
$available_for = unserialize($row["available_for"]);
if (!empty($available_for)) {
$row["type"] = "contributionStatus";
$row["pmb_name"] = $row["id"];
$row["available_for"] = $available_for;
self::$contribution_status[] = $row;
}
}
}
}
return self::$contribution_status;
}
public static function get_moderation_forms($user_id = 0) {
global $charset;
$query = "SELECT * WHERE {
?s ?contributor .
?s ?p ?o .
?s ?last_edit .
optional {
?s ?identifier
}
}
ORDER BY ?contributor DESC (?last_edit)";
$results = array ();
//Parse initial des résultats de la requete sparql
if (self::get_datastore()->query($query)) {
$rows = self::get_datastore()->get_result();
foreach ($rows as $row) {
if (empty($row->identifier)) {
if (!isset($results[$row->s])) {
$results[$row->s] = array ();
}
$results[$row->s][explode('#', $row->p)[1]] = $row->o;
if (empty($results[$row->s]["uri_id"])) {
$uri_id = onto_common_uri::get_id($row->s);
if (empty($uri_id)) {
$uri_id = onto_common_uri::set_new_uri($row->s);
}
$results[$row->s]["uri_id"] = $uri_id;
}
if (!isset($results[$row->s]["contributor"])) {
$results[$row->s]["contributor"] = $row->contributor;
}
}
}
}
return self::edit_results_to_template($results, false, 0);
}
public static function get_contributor_infos($contributor_id) {
$contributor_infos = array();
$contributor_id += 0;
if ($contributor_id) {
$contributor = new emprunteur($contributor_id);
$contributor_infos['id'] = $contributor->id;
$contributor_infos['name'] = $contributor->nom.' '.$contributor->prenom;
}
return $contributor_infos;
}
public static function get_empr_forms($id_empr, $validated_forms = false, $last_id = 0) {
global $charset;
$id_empr+= 0;
if (!$id_empr) {
return array();
}
$query = "SELECT * WHERE {
?s '" . $id_empr . "' .
?s ?p ?o .
?s ?last_edit
}
ORDER BY DESC (?last_edit)";
$results = array ();
//Parse initial des résultats de la requete sparql
if (self::get_datastore ()->query ( $query )) {
$rows = self::get_datastore ()->get_result ();
foreach ( $rows as $row ) {
if (! isset ( $results [$row->s] )) {
$results [$row->s] = array ();
}
$results [$row->s] [explode('#', $row->p)[1]] = htmlentities($row->o,ENT_QUOTES,$charset);
if (empty($results[$row->s]["uri_id"])) {
$uri_id = onto_common_uri::get_id($row->s);
if (empty($uri_id)) {
$uri_id = onto_common_uri::set_new_uri($row->s);
}
$results[$row->s]["uri_id"] = $uri_id;
}
}
}
return self::edit_results_to_template($results, $validated_forms, $last_id);
}
public static function get_area_infos($area_id) {
$area_infos = array();
$area_id += 0;
if ($area_id) {
$area = new contribution_area($area_id);
$area_infos['id'] = $area->get_id();
$area_infos['name'] = $area->get_title();
$area_infos['color'] = $area->get_color();
}
return $area_infos;
}
public static function get_link_from_type($type, $id, $bulletin = false) {
switch ($type) {
case 'http://www.pmbservices.fr/ontology#record' :
if ($bulletin){
$query = "SELECT bulletin_id FROM bulletins WHERE num_notice = '".$id."'";
$result = pmb_mysql_query($query);
if (pmb_mysql_num_rows($result)) {
$bulletin = pmb_mysql_fetch_object($result);
return './index.php?lvl=bulletin_display&id='.$bulletin->bulletin_id;
}
}
return './index.php?lvl=notice_display&id='.$id;
case 'http://www.pmbservices.fr/ontology#author' :
return './index.php?lvl=author_see&id='.$id;
case 'http://www.pmbservices.fr/ontology#category' :
return './index.php?lvl=categ_see&id='.$id;
case 'http://www.pmbservices.fr/ontology#collection' :
return './index.php?lvl=coll_see&id='.$id;
case 'http://www.w3.org/2004/02/skos/core#Concept' :
return './index.php?lvl=concept_see&id='.$id;
case 'http://www.pmbservices.fr/ontology#docnum' :
$query = 'SELECT explnum_notice, explnum_bulletin FROM explnum WHERE explnum_id = "'.$id.'"';
$result = pmb_mysql_query($query);
if (pmb_mysql_num_rows($result)) {
$row = pmb_mysql_fetch_object($result);
if ($row->explnum_notice) {
return './index.php?lvl=notice_display&id='.$row->explnum_notice;
} else {
return './index.php?lvl=bulletin_display&id='.$row->explnum_bulletin;
}
}
case 'http://www.pmbservices.fr/ontology#indexint' :
return './index.php?lvl=indexint_see&id='.$id;
case 'http://www.pmbservices.fr/ontology#publisher' :
return './index.php?lvl=publisher_see&id='.$id;
case 'http://www.pmbservices.fr/ontology#serie' :
return './index.php?lvl=serie_see&id='.$id;
case 'http://www.pmbservices.fr/ontology#sub_collection' :
return './index.php?lvl=subcoll_see&id='.$id;
case 'http://www.pmbservices.fr/ontology#work' :
return './index.php?lvl=titre_uniforme_see&id='.$id;
default :
return '#';
}
}
public static function edit_results_to_template($results,$validated_forms = false, $last_id = 0) {
global $msg, $charset, $pmb_contribution_opac_show_sub_form;
//gestion des droits
$returned_result = array ();
//Composition d'un résultat manipulable dans les templates
$onto = self::get_ontology();
foreach ($results as $form_uri => $properties_array) {
//droit sur l'espace
if (!empty($properties_array['area']) && isset($dom_4)) {
if (!$dom_4->getRights($_SESSION['id_empr_session'],$properties_array['area'], 4)) {
continue;
}
}
if (!$validated_forms && !empty($properties_array["identifier"])) {
continue;
} else if ($validated_forms && !isset($properties_array["identifier"])) {
continue;
}
if (!isset($returned_result[$onto->get_class_label($properties_array['type'])])) {
$returned_result [$onto->get_class_label($properties_array['type'])] = array ();
}
if (!isset($properties_array['entity_type'])) {
$properties_array['entity_type'] = $onto->get_class_label($properties_array['type']);
}
if (!empty($properties_array['last_edit'])) {
$properties_array['last_edit'] = date($msg['1005'].' H:i', $properties_array['last_edit']);
}
//infos de l'espace
if (!empty($properties_array['area'])) {
$properties_array['area'] = self::get_area_infos($properties_array['area']);
}
//id de l'entité en base SQL
if (!empty($properties_array['identifier'])) {
if (isset($properties_array['bibliographical_lvl']) && $properties_array['bibliographical_lvl'] == 'b') {
$properties_array['link'] = self::get_link_from_type($properties_array['type'], $properties_array['identifier'], true);
} else {
$properties_array['link'] = self::get_link_from_type($properties_array['type'], $properties_array['identifier']);
}
}
//infos du contributeur
if (!empty($properties_array['contributor'])) {
$contributor = self::get_contributor_infos($properties_array['contributor']);
$properties_array['contributor'] = $contributor;
$properties_array['contributor_id'] = $contributor['id'];
$properties_array['contributor_name'] = $contributor['name'];
}
$results[$form_uri] = $properties_array;
}
return $results;
}
public static function get_ontology() {
if(!isset(self::$ontology)){
self::$ontology = contribution_area::get_ontology();
}
return self::$ontology;
}
public static function mail_empr_contribution_validate($uri) {
global $msg, $charset, $opac_url_base, $include_path;
$store = new contribution_area_store();
$dataStore = $store->get_datastore();
$query = "SELECT * WHERE {
<".$uri."> ?id_contributor.
<".$uri."> ?last_edit.
<".$uri."> ?display_label.
}";
$dataStore->query($query);
$results = $dataStore->get_result();
// On va cherche l'emprunteur
$empr = new emprunteur($results[0]->id_contributor);
// Adresse mail de la loc de l'emprunteur
$requete = "select location_libelle, email, empr_location from empr, docs_location where empr_location=idlocation and id_empr='".$results[0]->id_contributor."'";
$res = pmb_mysql_query($requete);
$loc=pmb_mysql_fetch_object($res);
$PMBuseremail = $loc->email ;
// On commence a preparer le mail
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=".$charset."\n";
// On genere le template de mail
$template_path = $include_path."/templates/contribution_area/contribution_validate_mail.tpl.html";
if (file_exists($include_path."/templates/contribution_area/contribution_validate_mail.subst.tpl.html")) {
$template_path = $include_path."/templates/contribution_area/contribution_validate_mail.subst.tpl.html";
}
if ($empr->mail) {
$output_final = "" ;
$sujet = $msg['subject_mail_confirm_validate_contribution'];
$dateTime = new DateTime();
$last_edit = $dateTime->setTimestamp($results[0]->last_edit);
$messages = [
"subject" => $msg['subject_mail_confirm_validate_contribution'],
"url" => $msg['mail_confirm_contribution_url']
];
$url = $opac_url_base."empr.php?tab=contribution_area&lvl=contribution_area_done";
//on fait le rendu du template pour l'envoyer aux administrateur
$h2o = H2o_collection::get_instance($template_path);
$output_final .= $h2o->render(['empr' => $empr, 'isbd' => $results[0]->display_label, 'date_contrib' => $last_edit->format('d-m-Y'), 'msg' => $messages, 'url' => $url]);
//on envoi le mail
$res_envoi = mailpmb($empr->nom." ".$empr->prenom, $empr->mail, $sujet, $output_final, "", $PMBuseremail, $headers, "", "", 1);
}
}
} // end of contribution_area_forms_controller