X-Git-Url: http://git.dj3c1t.com/index.cgi?a=blobdiff_plain;f=app%2Fdata%2Fmodules%2Fsql%2Fsml_data_sources.php;h=ccb1a440eb1d9e3e0b70d37c3fbe60c3f4d91399;hb=HEAD;hp=8e8056e2bf07a04fbdc45302933401918860124b;hpb=9391cb9ccb3dd2884e7be2f15aa729733288f1e5;p=mw_sourceml diff --git a/app/data/modules/sql/sml_data_sources.php b/app/data/modules/sql/sml_data_sources.php index 8e8056e..ccb1a44 100644 --- a/app/data/modules/sql/sml_data_sources.php +++ b/app/data/modules/sql/sml_data_sources.php @@ -2,18 +2,18 @@ class sml_data_sources extends mw_data{ - var $status; + public $status; # ---------------------------------------------------------------------------------------- - # status de source + # classes de source # - function source_status(){ + public function source_status(){ if(!isset($this->status)) $this->status = $this->init_sources_status(); return $this->status; } - function init_sources_status(){ + public function init_sources_status(){ $sgbd = $this->sgbd(); $env = $this->env(); $status = array(); @@ -23,7 +23,9 @@ while($v_rst = $sgbd->fetch_assoc($rst)) $status[$v_rst["id"]] = $v_rst; $sgbd->free_result($rst); } - catch(Exception $e) { $status = false; } + catch(Exception $e){ + $status = false; + } return $status; } @@ -31,11 +33,11 @@ # sources # - function init_sources_table(){ + public function init_sources_table(){ return true; } - function sources($params){ + public function sources($params){ $start = isset($params["start"]) ? $params["start"] : null; $id_user = isset($params["id_user"]) ? $params["id_user"] : null; $id_groupe = isset($params["id_groupe"]) ? $params["id_groupe"] : null; @@ -44,6 +46,7 @@ $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null; $id_source_derivation = isset($params["id_source_derivation"]) ? $params["id_source_derivation"] : null; $id_licence = isset($params["id_licence"]) ? $params["id_licence"] : null; + $is_reference = isset($params["is_reference"]) ? $params["is_reference"] : null; $order_by = isset($params["order_by"]) ? $params["order_by"] : "ordre"; $order = isset($params["order"]) ? $params["order"] : "ASC"; $sgbd = $this->sgbd(); @@ -52,7 +55,7 @@ $ORDER_FROM_SOURCES_INFOS = !$ORDER_FIELD_EXISTS; $sources = array("list" => array(), "total" => 0); $COUNT_SELECT = "SELECT count(*) as n"; - $SELECT = "SELECT #--sml_sources.*, #--sml_sources.id_class as status"; + $SELECT = "SELECT #--sml_sources.*, #--sml_sources.id_class as `status`"; if($ORDER_FROM_SOURCES_INFOS){ if($order_by == "ordre"){ $SELECT .= ", (0 + #--sml_sources_infos.`value`) as ordre"; @@ -78,13 +81,13 @@ ($WHERE ? " AND " : " WHERE ") ." #--sml_sources.id=#--sml_sources_authors.id_source" ." AND #--sml_sources_authors.id_author=#--sml_authors.id" - ." AND #--sml_authors.id_user=".$this->eq($id_user) - ." AND #--sml_sources_authors.id_sources_access=".$this->id_groupe_status_admin(); + ." AND #--sml_authors.id_user=".$this->eq($id_user)/* + ." AND #--sml_sources_authors.id_sources_access=".$this->id_groupe_status_admin()*/; if(isset($id_groupe)) $WHERE .= ($WHERE ? " AND " : " WHERE ") ." #--sml_sources.id=#--sml_sources_authors.id_source" - ." AND #--sml_sources_authors.id_author=".$this->eq($id_groupe) - ." AND #--sml_sources_authors.id_sources_access=".$this->id_groupe_status_admin(); + ." AND #--sml_sources_authors.id_author=".$this->eq($id_groupe)/* + ." AND #--sml_sources_authors.id_sources_access=".$this->id_groupe_status_admin()*/; if(isset($status)) $WHERE .= ($WHERE ? " AND " : " WHERE ") ." #--sml_sources.id_class=".$this->eq($status); @@ -92,17 +95,17 @@ ($WHERE ? " AND " : " WHERE ") ." #--sml_sources.id=#--sml_source_compositions.id_composition" ." AND #--sml_source_compositions.id_source=".$this->eq($id_source); - elseif(isset($id_composition)) - { if($id_composition) - { $WHERE .= + elseif(isset($id_composition)){ + if($id_composition){ + $WHERE .= ($WHERE ? " AND " : " WHERE ") ." #--sml_sources.id=#--sml_source_compositions.id_source" ." AND #--sml_source_compositions.id_composition=".$this->eq($id_composition); } - else - { if(($sources_ids = $this->source_compositions(array("id_composition" => ""))) !== false) - { if($sources_ids) - { $NOT_IN = ""; + else{ + if(($sources_ids = $this->source_compositions(array("id_composition" => ""))) !== false){ + if($sources_ids){ + $NOT_IN = ""; foreach($sources_ids as $in_source_id) $NOT_IN .= ($NOT_IN ? "," : "").$in_source_id; $WHERE .= ($WHERE ? " AND " : " WHERE ")." #--sml_sources.id NOT IN(".$NOT_IN.")"; } @@ -117,6 +120,19 @@ if(isset($id_licence)) $WHERE .= ($WHERE ? " AND " : " WHERE ") ." #--sml_sources.licence=".$this->eq($id_licence); + if(isset($is_reference)){ + $WHERE .= ($WHERE ? " AND " : " WHERE "); + if($is_reference){ + $WHERE .= + " #--sml_sources.reference IS NOT NULL" + ." AND LENGTH(#--sml_sources.reference) > 0"; + } + else{ + $WHERE .= + " (#--sml_sources.reference IS NULL" + ." OR (LENGTH(#--sml_sources.reference) = 0))"; + } + } $ORDER_BY = " ORDER BY ".$order_by." ".$order; $LIMIT = (isset($start) && $env->config("max_list") ? " LIMIT ".$env->config("max_list")." OFFSET ".$start : ""); try{ @@ -124,8 +140,8 @@ $rst = $sgbd->query($sql); if($v_rst = $sgbd->fetch_assoc($rst)) $sources["total"] = $v_rst["n"]; $sgbd->free_result($rst); - if($sources["total"]) - { $sql = $SELECT.$FROM.$WHERE.$ORDER_BY.$LIMIT; + if($sources["total"]){ + $sql = $SELECT.$FROM.$WHERE.$ORDER_BY.$LIMIT; $rst = $sgbd->query($sql); $OK = true; while($v_rst = $sgbd->fetch_assoc($rst)){ @@ -138,11 +154,13 @@ if(!$OK) return false; } } - catch(Exception $e) { $sources = false; } + catch(Exception $e){ + $sources = false; + } return $sources; } - function source($id, $load = false){ + public function source($id, $load = false){ $sgbd = $this->sgbd(); try{ $sql = "SELECT #--sml_sources.*, #--sml_sources.id_class as status FROM #--sml_sources WHERE id=".$this->eq($id); @@ -153,11 +171,13 @@ } $sgbd->free_result($rst); } - catch(Exception $e) { $source = false; } + catch(Exception $e){ + $source = false; + } return $source; } - function get_source_from_v_rst($v_rst){ + public function get_source_from_v_rst($v_rst){ $sgbd = $this->sgbd(); $source = $this->empty_source(); foreach($v_rst as $rst_key => $rst_value) $source[$rst_key] = $rst_value; @@ -183,22 +203,24 @@ } } } - catch(Exception $e) { $source = false; } + catch(Exception $e){ + $source = false; + } return $source; } - function load_source($source){ + public function load_source($source){ $env = $this->env(); if(!isset($source["id"])) return false; $source = $this->get_source_from_v_rst($source); - $source["xml"] = array - ( "url" => $this->source_xml_url($source["id"]), + $source["xml"] = array( + "url" => $this->source_xml_url($source["id"]), "content" => $this->get_source_xml($source["id"]) ); $source["documents"] = array(); if(($source["groupes"] = $this->source_groupes($source["id"])) === false) return false; - $source["image_uri"] = - ( isset($source["image"]) && $source["image"] ? + $source["image_uri"] = ( + isset($source["image"]) && $source["image"] ? $env->path("content")."uploads/".$source["image"] : "" ); @@ -206,14 +228,17 @@ if(($source["has_derivations"] = $this->source_derivations(array("derivation" => $source["id"]))) === false) return false; if(($source["derivations"] = $this->source_derivations(array("id_source" => $source["id"]))) === false) return false; if(($source["reference"] = $this->source_reference($source)) === false) return false; - if(!$source["reference"]) - { if(($source["documents"] = $this->source_documents($source["id"])) === false) return false; + if($user = $env->user()){ + if(($source["permissions"] = $this->source_permissions($source, $user["id"])) === false) return false; + } + if(!$source["reference"]){ + if(($source["documents"] = $this->source_documents($source["id"])) === false) return false; } return $source; } - function add_source - ( $groupes, + public function add_source( + $groupes, $titre, $status, $licence, @@ -221,10 +246,10 @@ $reference = array(), $derivations = array(), $infos = array() - ) - { $sgbd = $this->sgbd(); - $source = array - ( "groupes" => $groupes, + ){ + $sgbd = $this->sgbd(); + $source = array( + "groupes" => $groupes, "titre" => $reference ? null : $titre, "status" => $status, "licence" => $reference ? null : $licence, @@ -245,9 +270,9 @@ .")"; $sgbd->query($sql); $id = $sgbd->insert_id(); - foreach($source["groupes"] as $id_groupe => $groupe) - { if($groupe["id"] && $groupe["id_groupe_status"]) - { if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false; + foreach($source["groupes"] as $id_groupe => $groupe){ + if($groupe["id"] && $groupe["id_groupe_status"]){ + if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false; } else return false; } @@ -264,37 +289,40 @@ $sgbd->query($sql); } } - catch(Exception $e) { return false; } - foreach($derivations as $source_derivation) - { if - ( ( $id_source_derivation = $this->add_source_derivation - ( $id, + catch(Exception $e){ + return false; + } + foreach($derivations as $source_derivation){ + if( + ( + $id_source_derivation = $this->add_source_derivation( + $id, $source_derivation["xml"]["url"], $source_derivation["xml"]["use_edit_content"] ? $source_derivation["xml"]["content"] : "" ) ) === false - ) - { return false; + ){ + return false; } } - if($reference) - { if($reference["xml"]["use_edit_content"]) - { if(!$this->set_edit_reference_content($id, $reference["xml"]["content"])) - { return false; + if($reference){ + if($reference["xml"]["use_edit_content"]){ + if(!$this->set_edit_reference_content($id, $reference["xml"]["content"])){ + return false; } } } - else - { foreach($documents as $document) - { if(!$this->add_source_document($id, $document)) return false; + else{ + foreach($documents as $document){ + if(!$this->add_source_document($id, $document)) return false; } } if(!$this->set_source_xml($id)) return false; return $id; } - function set_source - ( $id, + public function set_source( + $id, $groupes, $titre, $status, @@ -303,11 +331,11 @@ $reference = array(), $derivations = array(), $infos = array() - ) - { if($source = $this->source($id)) - { $sgbd = $this->sgbd(); - $source = array - ( "groupes" => $groupes, + ){ + if($source = $this->source($id)){ + $sgbd = $this->sgbd(); + $source = array( + "groupes" => $groupes, "titre" => $reference ? null : $titre, "licence" => $reference ? null : $licence, "reference" => $reference ? $reference : null, @@ -323,8 +351,8 @@ ." WHERE id=".$this->eq($id); $sgbd->query($sql); if(!$this->del_source_groupes($id)) return false; - foreach($source["groupes"] as $id_groupe => $groupe) - { if($groupe["id"] && $groupe["id_groupe_status"]){ + foreach($source["groupes"] as $id_groupe => $groupe){ + if($groupe["id"] && $groupe["id_groupe_status"]){ if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false; } else return false; @@ -333,8 +361,8 @@ $sgbd->query($sql); if(isset($infos["date_creation"])) unset($infos["date_creation"]); if(isset($infos["date_inscription"])) unset($infos["date_inscription"]); - foreach($infos as $key => $value) - { $sql = + foreach($infos as $key => $value){ + $sql = "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)" ." VALUES" ."( ".$this->eq($id) @@ -344,26 +372,29 @@ $sgbd->query($sql); } } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } if(!$this->del_source_derivations($id)) return false; if(!$this->del_edit_reference_content($id)) return false; if(!$this->del_source_documents($id)) return false; - foreach($derivations as $source_derivation) - { if - ( ( $id_source_derivation = $this->add_source_derivation - ( $id, + foreach($derivations as $source_derivation){ + if( + ( + $id_source_derivation = $this->add_source_derivation( + $id, $source_derivation["xml"]["url"], $source_derivation["xml"]["use_edit_content"] ? $source_derivation["xml"]["content"] : "" ) ) === false - ) - { return false; + ){ + return false; } } - if($reference) - { if($reference["xml"]["use_edit_content"]) - { if(!$this->set_edit_reference_content($id, $reference["xml"]["content"])) - { return false; + if($reference){ + if($reference["xml"]["use_edit_content"]){ + if(!$this->set_edit_reference_content($id, $reference["xml"]["content"])){ + return false; } } } @@ -378,7 +409,7 @@ return false; } - function set_source_info($id_source, $key, $value){ + public function set_source_info($id_source, $key, $value){ $sgbd = $this->sgbd(); try{ $sql = @@ -389,25 +420,31 @@ $id = null; if($v_rst = $sgbd->fetch_assoc($rst)) $id = $v_rst["id"]; $sgbd->free_result($rst); - if(isset($id)) $sql = - "UPDATE #--sml_sources_infos SET" - ." `value`=".$this->eq($value) - ." WHERE id=".$this->eq($id); - else $sql = - "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)" - ." VALUES" - ."( ".$this->eq($id_source) - .", ".$this->eq($key) - .", ".$this->eq($value) - .")"; + if(isset($id)){ + $sql = + "UPDATE #--sml_sources_infos SET" + ." `value`=".$this->eq($value) + ." WHERE id=".$this->eq($id); + } + else{ + $sql = + "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)" + ." VALUES" + ."( ".$this->eq($id_source) + .", ".$this->eq($key) + .", ".$this->eq($value) + .")"; + } $sgbd->query($sql); if(!isset($id)) $id = $sgbd->insert_id(); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $id; } - function del_source($id){ + public function del_source($id){ $sgbd = $this->sgbd(); if(!$this->del_source_compositions(array("id_source" => $id, "id_composition" => $id))) return false; if(!$this->del_edit_reference_content($id)) return false; @@ -421,7 +458,9 @@ $sql = "DELETE FROM #--sml_sources WHERE id=".$this->eq($id); $sgbd->query($sql); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return true; } @@ -429,12 +468,12 @@ # derivations de sources # - function init_source_derivations() - { $sgbd = $this->sgbd(); + public function init_source_derivations(){ + $sgbd = $this->sgbd(); $rst = $sgbd->table_exists("#--sml_source_derivations"); - if(isset($rst)) - { if(!$rst) - { return + if(isset($rst)){ + if(!$rst){ + return "table manquante" ."
" ."
" @@ -452,8 +491,8 @@ return true; } - function source_derivations($params) - { $sgbd = $this->sgbd(); + public function source_derivations($params){ + $sgbd = $this->sgbd(); $env = $this->env(); $derivations = array(); // sources dont "id_source" est une derivation @@ -464,14 +503,28 @@ ." FROM #--sml_source_derivations" ." WHERE #--sml_source_derivations.id_source=".$this->eq($params["id_source"]); $rst = $sgbd->query($sql); - while($v_rst = $sgbd->fetch_assoc($rst)) - { $derivations[$v_rst["id"]] = array(); + while($v_rst = $sgbd->fetch_assoc($rst)){ + $derivations[$v_rst["id"]] = array(); $derivation_edit_file = $this->derivation_edit_xml_path($v_rst["id_source"], $v_rst["id"]); - if(file_exists($derivation_edit_file)) - { if(($derivation_edit_content = $this->get_edit_derivation_content($v_rst["id_source"], $v_rst["id"])) !== false) - { if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"], $derivation_edit_content)) !==false) - { $derivations[$v_rst["id"]]["xml"] = array - ( "url" => $v_rst["derivation"], + if(file_exists($derivation_edit_file)){ + if( + ( + $derivation_edit_content = $this->get_edit_derivation_content( + $v_rst["id_source"], + $v_rst["id"] + ) + ) !== false + ){ + if( + ( + $derivations[$v_rst["id"]] = $this->source_xml_read( + $v_rst["derivation"], + $derivation_edit_content + ) + ) !==false + ){ + $derivations[$v_rst["id"]]["xml"] = array( + "url" => $v_rst["derivation"], "content" => $derivation_edit_content, "use_edit_content" => true ); @@ -480,9 +533,9 @@ } else return false; } - else - { if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"])) !==false) - { $derivations[$v_rst["id"]]["id_source"] = $v_rst["id_source"]; + else{ + if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"])) !==false){ + $derivations[$v_rst["id"]]["id_source"] = $v_rst["id_source"]; } else $derivations[$v_rst["id"]] = $this->empty_source(); } @@ -490,12 +543,14 @@ } $sgbd->free_result($rst); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $derivations; } // sources qui derivent de "derivation" - elseif(isset($params["derivation"])) - { $source_xml_url = $params["derivation"]; + elseif(isset($params["derivation"])){ + $source_xml_url = $params["derivation"]; if(preg_match("/^[0-9]+$/", $source_xml_url)) $source_xml_url = $this->source_xml_url($source_xml_url); try{ $sql = @@ -508,13 +563,15 @@ while($v_rst = $sgbd->fetch_assoc($rst)) $derivations[$v_rst["id"]] = $v_rst; $sgbd->free_result($rst); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $derivations; } return false; } - function source_derivation($id){ + public function source_derivation($id){ $sgbd = $this->sgbd(); $env = $this->env(); $derivation = array(); @@ -527,12 +584,14 @@ if($v_rst = $sgbd->fetch_assoc($rst)) $derivation = $v_rst; $sgbd->free_result($rst); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $derivation; } - function add_source_derivation($id_source, $derivation, $edit_content = "") - { $sgbd = $this->sgbd(); + public function add_source_derivation($id_source, $derivation, $edit_content = ""){ + $sgbd = $this->sgbd(); try{ $sql = "INSERT INTO #--sml_source_derivations(id_source, derivation)" @@ -543,17 +602,19 @@ $sgbd->query($sql); $id_source_derivation = $sgbd->insert_id(); } - catch(Exception $e) { return false; } - if($edit_content) - { if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content)) - { return false; + catch(Exception $e){ + return false; + } + if($edit_content){ + if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content)){ + return false; } } return $id_source_derivation; } - function set_source_derivation($id_source_derivation, $id_source, $derivation, $edit_content = "") - { $sgbd = $this->sgbd(); + public function set_source_derivation($id_source_derivation, $id_source, $derivation, $edit_content = ""){ + $sgbd = $this->sgbd(); try{ $sql = "UPDATE #--sml_source_derivations SET" @@ -562,26 +623,30 @@ ." WHERE id=".$this->eq($id_source_derivation); $sgbd->query($sql); } - catch(Exception $e) { return false; } - if($edit_content) - { if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content)) - { return false; + catch(Exception $e){ + return false; + } + if($edit_content){ + if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content)){ + return false; } } return true; } - function del_source_derivation($id_source_derivation) - { if(($derivation = $this->source_derivation($id_source_derivation)) !== false) - { if(($derivations = $this->source_derivations(array("id_source" => $derivation["id_source"]))) !== false) - { $sgbd = $this->sgbd(); + public function del_source_derivation($id_source_derivation){ + if(($derivation = $this->source_derivation($id_source_derivation)) !== false){ + if(($derivations = $this->source_derivations(array("id_source" => $derivation["id_source"]))) !== false){ + $sgbd = $this->sgbd(); try{ $sql = "DELETE FROM #--sml_source_derivations WHERE id=".$this->eq($id_source_derivation); $sgbd->query($sql); } - catch(Exception $e) { return false; } - if(count($derivations) > 1) - { return $this->del_edit_derivation_content($derivation["id_source"], $id_source_derivation); + catch(Exception $e){ + return false; + } + if(count($derivations) > 1){ + return $this->del_edit_derivation_content($derivation["id_source"], $id_source_derivation); } else return $this->del_edit_derivations($derivation["id_source"]); } @@ -589,13 +654,15 @@ return false; } - function del_source_derivations($id_source) - { $sgbd = $this->sgbd(); + public function del_source_derivations($id_source){ + $sgbd = $this->sgbd(); try{ $sql = "DELETE FROM #--sml_source_derivations WHERE id_source=".$this->eq($id_source); $sgbd->query($sql); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $this->del_edit_derivations($id_source); } @@ -603,22 +670,22 @@ # references # - function source_reference($source) - { $reference = array(); - if($source["reference"]) - { if(!is_array($source["reference"])) - { $source["reference"] = array - ( "url" => $source["reference"], + public function source_reference($source){ + $reference = array(); + if($source["reference"]){ + if(!is_array($source["reference"])){ + $source["reference"] = array( + "url" => $source["reference"], "content" => "", "use_edit_content" => false ); } $reference_edit_file = $this->reference_edit_xml_path($source["id"]); - if(file_exists($reference_edit_file)) - { if(($reference_edit_content = $this->get_edit_reference_content($source["id"])) !== false) - { if(($reference = $this->source_xml_read($source["reference"], $reference_edit_content)) !==false) - { $reference["xml"] = array - ( "url" => $source["reference"]["xml"]["url"], + if(file_exists($reference_edit_file)){ + if(($reference_edit_content = $this->get_edit_reference_content($source["id"])) !== false){ + if(($reference = $this->source_xml_read($source["reference"], $reference_edit_content)) !==false){ + $reference["xml"] = array( + "url" => $source["reference"]["xml"]["url"], "content" => $reference_edit_content, "use_edit_content" => true ); @@ -627,9 +694,9 @@ } else return false; } - else - { if(($reference = $this->source_xml_read($source["reference"]["xml"]["url"])) ===false) - { $reference = $this->empty_source(); + else{ + if(($reference = $this->source_xml_read($source["reference"]["xml"]["url"])) ===false){ + $reference = $this->empty_source(); } } } @@ -640,8 +707,8 @@ # documents # - function source_documents($id_source) - { $sgbd = $this->sgbd(); + public function source_documents($id_source){ + $sgbd = $this->sgbd(); $documents = array(); try{ $sql = "SELECT * FROM #--sml_source_documents WHERE id_source=".$this->eq($id_source); @@ -650,12 +717,14 @@ while($v_rst = $sgbd->fetch_assoc($rst)) $documents[$v_rst["id"]] = $v_rst; $sgbd->free_result($rst); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $documents; } - function add_source_document($id_source, $document) - { $sgbd = $this->sgbd(); + public function add_source_document($id_source, $document){ + $sgbd = $this->sgbd(); try{ $sql = "INSERT INTO #--sml_source_documents(id_source, nom, url)" @@ -666,17 +735,21 @@ .")"; $sgbd->query($sql); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $sgbd->insert_id(); } - function del_source_documents($id_source) - { $sgbd = $this->sgbd(); + public function del_source_documents($id_source){ + $sgbd = $this->sgbd(); try{ $sql = "DELETE FROM #--sml_source_documents WHERE id_source=".$this->eq($id_source); $sgbd->query($sql); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return true; } @@ -684,8 +757,8 @@ # compositions de sources # - function source_compositions($params) - { $id_source = isset($params["id_source"]) ? $params["id_source"] : null; + public function source_compositions($params){ + $id_source = isset($params["id_source"]) ? $params["id_source"] : null; $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null; $sgbd = $this->sgbd(); $env = $this->env(); @@ -694,28 +767,32 @@ try{ $sql = "SELECT * FROM #--sml_source_compositions WHERE id_source=".$this->eq($id_source); $rst = $sgbd->query($sql); - while($v_rst = $sgbd->fetch_assoc($rst)) - { if(!isset($compositions[$v_rst["id_source"]])) $compositions[$v_rst["id_source"]] = array(); + while($v_rst = $sgbd->fetch_assoc($rst)){ + if(!isset($compositions[$v_rst["id_source"]])) $compositions[$v_rst["id_source"]] = array(); $compositions[$v_rst["id_source"]][] = $v_rst["id_composition"]; } $sgbd->free_result($rst); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $compositions; } - elseif(isset($id_composition)) - { if($id_composition){ + elseif(isset($id_composition)){ + if($id_composition){ try{ $sql = "SELECT * FROM #--sml_source_compositions WHERE id_composition=".$this->eq($id_composition); $rst = $sgbd->query($sql); - while($v_rst = $sgbd->fetch_assoc($rst)) - { if(!isset($compositions[$v_rst["id_composition"]])) $compositions[$v_rst["id_composition"]] = array(); + while($v_rst = $sgbd->fetch_assoc($rst)){ + if(!isset($compositions[$v_rst["id_composition"]])) $compositions[$v_rst["id_composition"]] = array(); $compositions[$v_rst["id_composition"]][] = $v_rst["id_source"]; } $sgbd->free_result($rst); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $compositions; } else{ @@ -726,14 +803,16 @@ while($v_rst = $sgbd->fetch_assoc($rst)) $compositions[] = $v_rst["id_source"]; $sgbd->free_result($rst); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $compositions; } } return false; } - function set_source_composition($id_source, $id_composition){ + public function set_source_composition($id_source, $id_composition){ $sgbd = $this->sgbd(); try{ $sql = @@ -743,11 +822,13 @@ .")"; $sgbd->query($sql); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $this->set_source_xml($id_composition); } - function del_source_compositions($params){ + public function del_source_compositions($params){ $res = true; $id_source = isset($params["id_source"]) ? $params["id_source"] : null; $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null; @@ -762,7 +843,9 @@ while($v_rst = $sgbd->fetch_assoc($rst)) $to_update[] = $v_rst["id_composition"]; $sgbd->free_result($rst); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } } try{ $sql = "DELETE FROM #--sml_source_compositions"; @@ -772,15 +855,17 @@ $sql .= $WHERE; $sgbd->query($sql); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } foreach($to_update as $id_source_xml){ if(!$this->set_source_xml($id_source_xml)) return false; } return true; } - function has_sources($id_composition) - { $sgbd = $this->sgbd(); + public function has_sources($id_composition){ + $sgbd = $this->sgbd(); $env = $this->env(); try{ $sql = "SELECT count(*) as n FROM #--sml_source_compositions WHERE id_composition=".$this->eq($id_composition); @@ -789,17 +874,18 @@ if($v_rst = $sgbd->fetch_assoc($rst)) $has_sources = $v_rst["n"]; $sgbd->free_result($rst); } - catch(Exception $e) { return false; } + catch(Exception $e){ + return false; + } return $has_sources; } - function source_ariane($id_source, $ariane = array()) - { if(($compositions = $this->source_compositions(array("id_source" => $id_source))) !== false) - { if(isset($compositions[$id_source]) && $compositions[$id_source]) - { foreach($compositions[$id_source] as $id_composition) - { if(($ariane = $this->source_ariane($id_composition, $ariane)) !== false) - { if(($ariane[$id_composition] = $this->source($id_composition)) !== false) - { + public function source_ariane($id_source, $ariane = array()){ + if(($compositions = $this->source_compositions(array("id_source" => $id_source))) !== false){ + if(isset($compositions[$id_source]) && $compositions[$id_source]){ + foreach($compositions[$id_source] as $id_composition){ + if(($ariane = $this->source_ariane($id_composition, $ariane)) !== false){ + if(($ariane[$id_composition] = $this->source($id_composition)) !== false){ } else $ariane = false; } @@ -813,5 +899,3 @@ } } - -?> \ No newline at end of file