item->set_contribution_area_form(contribution_area_form::get_contribution_area_form($this->params->sub,$this->params->form_id,$this->params->area_id,$this->params->form_uri));
print $this->item->get_form("./".$this->get_base_resource()."lvl=".$this->params->lvl."&sub=".$this->params->sub."&area_id=".$this->params->area_id."&id=".$this->params->id.'&form_id='.$this->params->form_id.'&form_uri='.$this->params->form_uri);
}
public function proceed($last_item = true){
global $msg, $lvl_redirect, $unauthorized_ids;
//on affecte la proprité item par une instance si nécessaire...
$this->init_item();
switch($this->params->action){
case 'push':
if ($last_item) {
print $msg["onto_contribution_push_in_progress"];
}
$data = $this->proceed_push();
if ($last_item) {
if (!empty($unauthorized_ids)) {
print "";
}else{
print "";
}
}
break;
case 'save_push' :
print encoding_normalize::json_encode($this->proceed_push());
break;
case 'save' :
print encoding_normalize::json_encode($this->proceed_save());
break;
case "save_draft" :
print encoding_normalize::json_encode($this->proceed_save(false, true));
break;
case 'delete' :
global $ajax;
if ($last_item && !$ajax) {
print $msg["onto_contribution_delete_in_progress"];
}
$return = $this->proceed_delete(true);
if ($last_item && !$ajax) {
print "";
}
if ($ajax){
$retour = [
'success' => !empty($return) ? true : false,
'error' => !empty($return) ? false : true,
'id' => $this->item->get_id(),
'displayLabel' =>'',
'uri'=>''
];
ajax_http_send_response(json_encode($retour));
}
break;
case "edit_entity" :
$this->proceed_edit_entity();
break;
default:
parent::proceed();
break;
}
}
protected function proceed_push() {
global $class_path;
global $pmb_contribution_ws_url, $pmb_contribution_ws_username, $pmb_contribution_ws_password;
$return = array();
if ($this->params->action == "save_push") {
$return = $this->proceed_save(false);
}
require_once($class_path.'/jsonRPCClient.php');
$jsonRPC = new jsonRPCClient(stripslashes($pmb_contribution_ws_url));
$jsonRPC->setUser(stripslashes($pmb_contribution_ws_username));
$jsonRPC->setPwd(stripslashes($pmb_contribution_ws_password));
$result = $jsonRPC->pmbesContributions_integrate_entity($this->item->get_uri());
if (!$return) {
$return = array("uri" => $this->item->get_uri(), "id" => $this->item->get_id());
}
$return["entity"] = $result;
//on enregitre un triplet faisant le lien entre l'URI et l'id de l'entité créée
$data_store = $this->handler->get_data_store();
$this->save_entity_id_in_store($result, $data_store);
if (!empty($return) && !empty($return['id'])) {
if ($this->params->action == 'push'){
contribution_area_forms_controller::mail_empr_contribution_validate($this->item->get_uri());
}
// Une fois la contribution validé on store plus aucune donner dans le store
$this->proceed_delete(true);
}
return $return;
}
/**
* On enregitre les triplets faisant le lien entre l'URI et l'id des entités créées
* @param array $data Tableau des entités à insérer sous la forme uri, id, children
* @param onto_store $data_store Store dans lequel on agit
*/
protected function save_entity_id_in_store($data, $data_store) {
$query = ' select ?pmb_id where {
<'.$data['uri'].'> pmb:identifier "'.$data["id"].'" .
<'.$data['uri'].'> pmb:identifier ?pmb_id
}';
$data_store->query($query);
if (!$data_store->num_rows()) {
$query_insert = 'insert into {
<'.$data['uri'].'> pmb:identifier "'.$data["id"].'" .
}';
$data_store->query($query_insert);
}
if (!empty($data['children'])) {
foreach ($data['children'] as $child) {
$this->save_entity_id_in_store($child, $data_store);
}
}
}
protected function proceed_save($list = true, $draft = false) {
$this->item->get_values_from_form();
$result = $this->handler->save($this->item, $draft);
if ($result !== true) {
$ui_class_name=self::resolve_ui_class_name($this->params->sub,$this->handler->get_onto_name());
$ui_class_name::display_errors($this,$result);
} else {
$display_label = $this->item->get_label($this->handler->get_display_labels($this->handler->get_class_uri($this->params->sub)));
$data = array(
"uri" => $this->item->get_uri(),
"displayLabel" => $display_label,
"id" => $this->item->get_id()
);
if ($draft) {
$data['draft_identifier'] = $this->item->get_draft_identifier();
$last_edit = new DateTime();
$data['date'] = $last_edit->format('d/m/Y');
$data['time'] = $last_edit->format('H:i:s');
}
if ("save" == $this->params->action) {
contribution_area_forms_controller::alert_mail_users_pmb();
}
return $data;
}
}
protected function proceed_delete($force_delete = false){
global $ajax;
$result = $this->handler->delete($this->item, $force_delete);
if ($this->item->onto_class->pmb_name == "docnum") {
$this->item->remove_file_uploads();
}
if ($ajax){
return $result;
}
}
protected function proceed_edit_entity(){
$this->item->set_contribution_area_form(contribution_area_form::get_contribution_area_form($this->params->sub,$this->params->form_id,$this->params->area_id,$this->params->form_uri));
$this->item->set_assertions(rdf_entities_converter_controller::convert($this->params->id, $this->params->sub, $this->params->item_uri));
$this->item->set_identifier($this->params->id);
print $this->item->get_form_entity("./".$this->get_base_resource()."lvl=".$this->params->lvl."&sub=".$this->params->sub."&area_id=".$this->params->area_id."&id=".$this->params->id.'&form_id='.$this->params->form_id.'&form_uri='.$this->params->form_uri);
}
protected function init_item() {
if (!intval($this->params->id)) {
$this->params->id = onto_common_uri::get_id($this->params->id);
}
switch ($this->params->action) {
case 'edit_entity':
$this->params->item_uri = onto_common_uri::get_new_uri('http://www.pmbservices.fr/ontology/'.$this->params->type.'#');
$this->item = $this->handler->get_item($this->handler->get_class_uri($this->params->sub), $this->params->item_uri);
break;
default:
parent::init_item();
break;
}
}
}