3 class sml_data_sources extends mw_data{
7 # ----------------------------------------------------------------------------------------
11 function source_status(){
12 if(!isset($this->status)) $this->status = $this->init_sources_status();
16 function init_sources_status(){
17 $sgbd = $this->sgbd();
21 $sql = "SELECT * FROM #--sml_classes";
22 $rst = $sgbd->query($sql);
23 while($v_rst = $sgbd->fetch_assoc($rst)) $status[$v_rst["id"]] = $v_rst;
24 $sgbd->free_result($rst);
26 catch(Exception $e) { $status = false; }
30 # ----------------------------------------------------------------------------------------
34 function init_sources_table(){
38 function sources($params){
39 $start = isset($params["start"]) ? $params["start"] : null;
40 $id_user = isset($params["id_user"]) ? $params["id_user"] : null;
41 $id_groupe = isset($params["id_groupe"]) ? $params["id_groupe"] : null;
42 $status = isset($params["status"]) ? $params["status"] : null;
43 $id_source = isset($params["id_source"]) ? $params["id_source"] : null;
44 $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null;
45 $id_source_derivation = isset($params["id_source_derivation"]) ? $params["id_source_derivation"] : null;
46 $id_licence = isset($params["id_licence"]) ? $params["id_licence"] : null;
47 $is_reference = isset($params["is_reference"]) ? $params["is_reference"] : null;
48 $order_by = isset($params["order_by"]) ? $params["order_by"] : "ordre";
49 $order = isset($params["order"]) ? $params["order"] : "ASC";
50 $sgbd = $this->sgbd();
52 $ORDER_FIELD_EXISTS = false;
53 $ORDER_FROM_SOURCES_INFOS = !$ORDER_FIELD_EXISTS;
54 $sources = array("list" => array(), "total" => 0);
55 $COUNT_SELECT = "SELECT count(*) as n";
56 $SELECT = "SELECT #--sml_sources.*, #--sml_sources.id_class as `status`";
57 if($ORDER_FROM_SOURCES_INFOS){
58 if($order_by == "ordre"){
59 $SELECT .= ", (0 + #--sml_sources_infos.`value`) as ordre";
62 $SELECT .= ", #--sml_sources_infos.`value` as ".$this->eq($order_by, false);
65 $FROM = "#--sml_sources";
66 if(isset($id_user)) $FROM .= ", #--sml_authors, #--sml_sources_authors";
67 elseif(isset($id_groupe)) $FROM .= ", #--sml_sources_authors";
68 if(isset($id_source)) $FROM .= ", #--sml_source_compositions";
69 elseif(isset($id_composition) && $id_composition) $FROM .= ", #--sml_source_compositions";
70 if(isset($id_source_derivation)) $FROM .= ", #--sml_source_derivations";
71 $FROM = " FROM (".$FROM.")";
72 if($ORDER_FROM_SOURCES_INFOS){
74 " LEFT JOIN #--sml_sources_infos"
75 ." ON (#--sml_sources_infos.id_source=#--sml_sources.id AND #--sml_sources_infos.`key`=".$this->eq($order_by).")";
78 if(isset($id_user)) $WHERE .=
79 ($WHERE ? " AND " : " WHERE ")
80 ." #--sml_sources.id=#--sml_sources_authors.id_source"
81 ." AND #--sml_sources_authors.id_author=#--sml_authors.id"
82 ." AND #--sml_authors.id_user=".$this->eq($id_user)/*
83 ." AND #--sml_sources_authors.id_sources_access=".$this->id_groupe_status_admin()*/;
84 if(isset($id_groupe)) $WHERE .=
85 ($WHERE ? " AND " : " WHERE ")
86 ." #--sml_sources.id=#--sml_sources_authors.id_source"
87 ." AND #--sml_sources_authors.id_author=".$this->eq($id_groupe)/*
88 ." AND #--sml_sources_authors.id_sources_access=".$this->id_groupe_status_admin()*/;
89 if(isset($status)) $WHERE .=
90 ($WHERE ? " AND " : " WHERE ")
91 ." #--sml_sources.id_class=".$this->eq($status);
92 if(isset($id_source)) $WHERE .=
93 ($WHERE ? " AND " : " WHERE ")
94 ." #--sml_sources.id=#--sml_source_compositions.id_composition"
95 ." AND #--sml_source_compositions.id_source=".$this->eq($id_source);
96 elseif(isset($id_composition))
99 ($WHERE ? " AND " : " WHERE ")
100 ." #--sml_sources.id=#--sml_source_compositions.id_source"
101 ." AND #--sml_source_compositions.id_composition=".$this->eq($id_composition);
104 { if(($sources_ids = $this->source_compositions(array("id_composition" => ""))) !== false)
107 foreach($sources_ids as $in_source_id) $NOT_IN .= ($NOT_IN ? "," : "").$in_source_id;
108 $WHERE .= ($WHERE ? " AND " : " WHERE ")." #--sml_sources.id NOT IN(".$NOT_IN.")";
114 if(isset($id_source_derivation)) $WHERE .=
115 ($WHERE ? " AND " : " WHERE ")
116 ." #--sml_sources.id=#--sml_source_derivations.id_source"
117 ." AND #--sml_source_derivations.derivation=".$this->eq($this->source_xml_url($id_source_derivation));
118 if(isset($id_licence)) $WHERE .=
119 ($WHERE ? " AND " : " WHERE ")
120 ." #--sml_sources.licence=".$this->eq($id_licence);
121 if(isset($is_reference)){
122 $WHERE .= ($WHERE ? " AND " : " WHERE ");
125 " #--sml_sources.reference IS NOT NULL"
126 ." AND LENGTH(#--sml_sources.reference) > 0";
130 " (#--sml_sources.reference IS NULL"
131 ." OR (LENGTH(#--sml_sources.reference) = 0))";
134 $ORDER_BY = " ORDER BY ".$order_by." ".$order;
135 $LIMIT = (isset($start) && $env->config("max_list") ? " LIMIT ".$env->config("max_list")." OFFSET ".$start : "");
137 $sql = $COUNT_SELECT.$FROM.$WHERE;
138 $rst = $sgbd->query($sql);
139 if($v_rst = $sgbd->fetch_assoc($rst)) $sources["total"] = $v_rst["n"];
140 $sgbd->free_result($rst);
141 if($sources["total"])
142 { $sql = $SELECT.$FROM.$WHERE.$ORDER_BY.$LIMIT;
143 $rst = $sgbd->query($sql);
145 while($v_rst = $sgbd->fetch_assoc($rst)){
146 if(($sources["list"][$v_rst["id"]] = $this->load_source($v_rst)) === false){
151 $sgbd->free_result($rst);
152 if(!$OK) return false;
155 catch(Exception $e) { $sources = false; }
159 function source($id, $load = false){
160 $sgbd = $this->sgbd();
162 $sql = "SELECT #--sml_sources.*, #--sml_sources.id_class as status FROM #--sml_sources WHERE id=".$this->eq($id);
163 $rst = $sgbd->query($sql);
165 if($v_rst = $sgbd->fetch_assoc($rst)){
166 $source = $load ? $this->load_source($v_rst) : $this->get_source_from_v_rst($v_rst);
168 $sgbd->free_result($rst);
170 catch(Exception $e) { $source = false; }
174 function get_source_from_v_rst($v_rst){
175 $sgbd = $this->sgbd();
176 $source = $this->empty_source();
177 foreach($v_rst as $rst_key => $rst_value) $source[$rst_key] = $rst_value;
179 $si_sql = "SELECT * FROM #--sml_sources_infos WHERE id_source=".$this->eq($source["id"]);
180 $si_rst = $sgbd->query($si_sql);
181 while($v_si_rst = $sgbd->fetch_assoc($si_rst)){
182 if(!isset($source[$v_si_rst["key"]])) $source[$v_si_rst["key"]] = $v_si_rst["value"];
184 $sgbd->free_result($si_rst);
185 if($source["reference"]){
186 if(!is_array($source["reference"])){
187 $reference_url = $source["reference"];
188 $source["reference"] = $this->empty_source();
189 $source["reference"]["xml"]["url"] = $reference_url;
193 if(!is_array($source["licence"])){
194 $source["licence"] = array(
195 "id" => $source["licence"]
200 catch(Exception $e) { $source = false; }
204 function load_source($source){
206 if(!isset($source["id"])) return false;
207 $source = $this->get_source_from_v_rst($source);
208 $source["xml"] = array
209 ( "url" => $this->source_xml_url($source["id"]),
210 "content" => $this->get_source_xml($source["id"])
212 $source["documents"] = array();
213 if(($source["groupes"] = $this->source_groupes($source["id"])) === false) return false;
214 $source["image_uri"] =
215 ( isset($source["image"]) && $source["image"] ?
216 $env->path("content")."uploads/".$source["image"]
219 if(($source["has_sources"] = $this->has_sources($source["id"])) === false) return false;
220 if(($source["has_derivations"] = $this->source_derivations(array("derivation" => $source["id"]))) === false) return false;
221 if(($source["derivations"] = $this->source_derivations(array("id_source" => $source["id"]))) === false) return false;
222 if(($source["reference"] = $this->source_reference($source)) === false) return false;
223 if($user = $env->user()){
224 if(($source["permissions"] = $this->source_permissions($source, $user["id"])) === false) return false;
226 if(!$source["reference"])
227 { if(($source["documents"] = $this->source_documents($source["id"])) === false) return false;
237 $documents = array(),
238 $reference = array(),
239 $derivations = array(),
242 { $sgbd = $this->sgbd();
244 ( "groupes" => $groupes,
245 "titre" => $reference ? null : $titre,
247 "licence" => $reference ? null : $licence,
248 "reference" => $reference ? $reference : null,
249 "date_creation" => isset($infos["date_creation"]) ? $infos["date_creation"] : null,
250 "date_inscription" => isset($infos["date_inscription"]) ? $infos["date_inscription"] : date("Y-m-d")
254 "INSERT INTO #--sml_sources(id_class, reference, titre, licence, date_creation, date_inscription)"
256 ."( ".$this->eq($source["status"])
257 .", ".$this->eq($source["reference"] ? $source["reference"]["xml"]["url"] : null)
258 .", ".$this->eq($source["titre"])
259 .", ".$this->eq($source["licence"])
260 .", ".$this->eq($source["date_creation"])
261 .", ".$this->eq($source["date_inscription"])
264 $id = $sgbd->insert_id();
265 foreach($source["groupes"] as $id_groupe => $groupe)
266 { if($groupe["id"] && $groupe["id_groupe_status"])
267 { if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false;
271 if(isset($infos["date_creation"])) unset($infos["date_creation"]);
272 if(isset($infos["date_inscription"])) unset($infos["date_inscription"]);
273 foreach($infos as $key => $value){
275 "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
278 .", ".$this->eq($key)
279 .", ".$this->eq($value)
284 catch(Exception $e) { return false; }
285 foreach($derivations as $source_derivation)
287 ( ( $id_source_derivation = $this->add_source_derivation
289 $source_derivation["xml"]["url"],
290 $source_derivation["xml"]["use_edit_content"] ? $source_derivation["xml"]["content"] : ""
298 { if($reference["xml"]["use_edit_content"])
299 { if(!$this->set_edit_reference_content($id, $reference["xml"]["content"]))
305 { foreach($documents as $document)
306 { if(!$this->add_source_document($id, $document)) return false;
309 if(!$this->set_source_xml($id)) return false;
319 $documents = array(),
320 $reference = array(),
321 $derivations = array(),
324 { if($source = $this->source($id))
325 { $sgbd = $this->sgbd();
327 ( "groupes" => $groupes,
328 "titre" => $reference ? null : $titre,
329 "licence" => $reference ? null : $licence,
330 "reference" => $reference ? $reference : null,
331 "date_creation" => isset($infos["date_creation"]) ? $infos["date_creation"] : null
335 "UPDATE #--sml_sources SET"
336 ." reference=".$this->eq($source["reference"] ? $source["reference"]["xml"]["url"] : null)
337 .", titre=".$this->eq($source["titre"])
338 .", licence=".$this->eq($source["licence"])
339 .", date_creation=".$this->eq($source["date_creation"])
340 ." WHERE id=".$this->eq($id);
342 if(!$this->del_source_groupes($id)) return false;
343 foreach($source["groupes"] as $id_groupe => $groupe)
344 { if($groupe["id"] && $groupe["id_groupe_status"]){
345 if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false;
349 $sql = "DELETE FROM #--sml_sources_infos WHERE id_source=".$this->eq($id);
351 if(isset($infos["date_creation"])) unset($infos["date_creation"]);
352 if(isset($infos["date_inscription"])) unset($infos["date_inscription"]);
353 foreach($infos as $key => $value)
355 "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
358 .", ".$this->eq($key)
359 .", ".$this->eq($value)
364 catch(Exception $e) { return false; }
365 if(!$this->del_source_derivations($id)) return false;
366 if(!$this->del_edit_reference_content($id)) return false;
367 if(!$this->del_source_documents($id)) return false;
368 foreach($derivations as $source_derivation)
370 ( ( $id_source_derivation = $this->add_source_derivation
372 $source_derivation["xml"]["url"],
373 $source_derivation["xml"]["use_edit_content"] ? $source_derivation["xml"]["content"] : ""
381 { if($reference["xml"]["use_edit_content"])
382 { if(!$this->set_edit_reference_content($id, $reference["xml"]["content"]))
388 foreach($documents as $document){
389 if(!$this->add_source_document($id, $document)) return false;
392 if(!$this->set_source_xml($id)) return false;
398 function set_source_info($id_source, $key, $value){
399 $sgbd = $this->sgbd();
402 "SELECT id FROM #--sml_sources_infos"
403 ." WHERE id_source=".$this->eq($id_source)
404 ." AND `key`=".$this->eq($key);
405 $rst = $sgbd->query($sql);
407 if($v_rst = $sgbd->fetch_assoc($rst)) $id = $v_rst["id"];
408 $sgbd->free_result($rst);
409 if(isset($id)) $sql =
410 "UPDATE #--sml_sources_infos SET"
411 ." `value`=".$this->eq($value)
412 ." WHERE id=".$this->eq($id);
414 "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
416 ."( ".$this->eq($id_source)
417 .", ".$this->eq($key)
418 .", ".$this->eq($value)
421 if(!isset($id)) $id = $sgbd->insert_id();
423 catch(Exception $e) { return false; }
427 function del_source($id){
428 $sgbd = $this->sgbd();
429 if(!$this->del_source_compositions(array("id_source" => $id, "id_composition" => $id))) return false;
430 if(!$this->del_edit_reference_content($id)) return false;
431 if(!$this->del_source_derivations($id)) return false;
432 if(!$this->del_source_xml($id)) return false;
433 if(!$this->del_source_documents($id)) return false;
434 if(!$this->del_source_groupes($id)) return false;
436 $sql = "DELETE FROM #--sml_sources_infos WHERE id_source=".$this->eq($id);
438 $sql = "DELETE FROM #--sml_sources WHERE id=".$this->eq($id);
441 catch(Exception $e) { return false; }
445 # ----------------------------------------------------------------------------------------
446 # derivations de sources
449 function init_source_derivations()
450 { $sgbd = $this->sgbd();
451 $rst = $sgbd->table_exists("#--sml_source_derivations");
459 ."(table_prefix)source_derivations :\n"
461 ." id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,\n"
462 ." id_source INT NOT NULL,\n"
463 ." derivation VARCHAR NOT NULL\n"
468 else return "impossible de chercher la table #--sml_source_derivations";
472 function source_derivations($params)
473 { $sgbd = $this->sgbd();
475 $derivations = array();
476 // sources dont "id_source" est une derivation
477 if(isset($params["id_source"])){
481 ." FROM #--sml_source_derivations"
482 ." WHERE #--sml_source_derivations.id_source=".$this->eq($params["id_source"]);
483 $rst = $sgbd->query($sql);
484 while($v_rst = $sgbd->fetch_assoc($rst))
485 { $derivations[$v_rst["id"]] = array();
486 $derivation_edit_file = $this->derivation_edit_xml_path($v_rst["id_source"], $v_rst["id"]);
487 if(file_exists($derivation_edit_file))
488 { if(($derivation_edit_content = $this->get_edit_derivation_content($v_rst["id_source"], $v_rst["id"])) !== false)
489 { if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"], $derivation_edit_content)) !==false)
490 { $derivations[$v_rst["id"]]["xml"] = array
491 ( "url" => $v_rst["derivation"],
492 "content" => $derivation_edit_content,
493 "use_edit_content" => true
501 { if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"])) !==false)
502 { $derivations[$v_rst["id"]]["id_source"] = $v_rst["id_source"];
504 else $derivations[$v_rst["id"]] = $this->empty_source();
506 $derivations[$v_rst["id"]]["id_source"] = $v_rst["id_source"];
508 $sgbd->free_result($rst);
510 catch(Exception $e) { return false; }
513 // sources qui derivent de "derivation"
514 elseif(isset($params["derivation"]))
515 { $source_xml_url = $params["derivation"];
516 if(preg_match("/^[0-9]+$/", $source_xml_url)) $source_xml_url = $this->source_xml_url($source_xml_url);
519 "SELECT #--sml_sources.*"
520 ." FROM #--sml_sources, #--sml_source_derivations"
521 ." WHERE #--sml_sources.id=#--sml_source_derivations.id_source"
522 ." AND #--sml_source_derivations.derivation=".$this->eq($source_xml_url);
523 $rst = $sgbd->query($sql);
524 if(!isset($rst)) return false;
525 while($v_rst = $sgbd->fetch_assoc($rst)) $derivations[$v_rst["id"]] = $v_rst;
526 $sgbd->free_result($rst);
528 catch(Exception $e) { return false; }
534 function source_derivation($id){
535 $sgbd = $this->sgbd();
537 $derivation = array();
541 ." FROM #--sml_source_derivations"
542 ." WHERE #--sml_source_derivations.id=".$this->eq($id);
543 $rst = $sgbd->query($sql);
544 if($v_rst = $sgbd->fetch_assoc($rst)) $derivation = $v_rst;
545 $sgbd->free_result($rst);
547 catch(Exception $e) { return false; }
551 function add_source_derivation($id_source, $derivation, $edit_content = "")
552 { $sgbd = $this->sgbd();
555 "INSERT INTO #--sml_source_derivations(id_source, derivation)"
557 ."( ".$this->eq($id_source)
558 .", ".$this->eq($derivation)
561 $id_source_derivation = $sgbd->insert_id();
563 catch(Exception $e) { return false; }
565 { if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content))
569 return $id_source_derivation;
572 function set_source_derivation($id_source_derivation, $id_source, $derivation, $edit_content = "")
573 { $sgbd = $this->sgbd();
576 "UPDATE #--sml_source_derivations SET"
577 ." id_source=".$this->eq($id_source)
578 .", derivation=".$this->eq($derivation)
579 ." WHERE id=".$this->eq($id_source_derivation);
582 catch(Exception $e) { return false; }
584 { if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content))
591 function del_source_derivation($id_source_derivation)
592 { if(($derivation = $this->source_derivation($id_source_derivation)) !== false)
593 { if(($derivations = $this->source_derivations(array("id_source" => $derivation["id_source"]))) !== false)
594 { $sgbd = $this->sgbd();
596 $sql = "DELETE FROM #--sml_source_derivations WHERE id=".$this->eq($id_source_derivation);
599 catch(Exception $e) { return false; }
600 if(count($derivations) > 1)
601 { return $this->del_edit_derivation_content($derivation["id_source"], $id_source_derivation);
603 else return $this->del_edit_derivations($derivation["id_source"]);
609 function del_source_derivations($id_source)
610 { $sgbd = $this->sgbd();
612 $sql = "DELETE FROM #--sml_source_derivations WHERE id_source=".$this->eq($id_source);
615 catch(Exception $e) { return false; }
616 return $this->del_edit_derivations($id_source);
619 # ----------------------------------------------------------------------------------------
623 function source_reference($source)
624 { $reference = array();
625 if($source["reference"])
626 { if(!is_array($source["reference"]))
627 { $source["reference"] = array
628 ( "url" => $source["reference"],
630 "use_edit_content" => false
633 $reference_edit_file = $this->reference_edit_xml_path($source["id"]);
634 if(file_exists($reference_edit_file))
635 { if(($reference_edit_content = $this->get_edit_reference_content($source["id"])) !== false)
636 { if(($reference = $this->source_xml_read($source["reference"], $reference_edit_content)) !==false)
637 { $reference["xml"] = array
638 ( "url" => $source["reference"]["xml"]["url"],
639 "content" => $reference_edit_content,
640 "use_edit_content" => true
648 { if(($reference = $this->source_xml_read($source["reference"]["xml"]["url"])) ===false)
649 { $reference = $this->empty_source();
656 # ----------------------------------------------------------------------------------------
660 function source_documents($id_source)
661 { $sgbd = $this->sgbd();
662 $documents = array();
664 $sql = "SELECT * FROM #--sml_source_documents WHERE id_source=".$this->eq($id_source);
665 $rst = $sgbd->query($sql);
666 if(!isset($rst)) return false;
667 while($v_rst = $sgbd->fetch_assoc($rst)) $documents[$v_rst["id"]] = $v_rst;
668 $sgbd->free_result($rst);
670 catch(Exception $e) { return false; }
674 function add_source_document($id_source, $document)
675 { $sgbd = $this->sgbd();
678 "INSERT INTO #--sml_source_documents(id_source, nom, url)"
680 ."( ".$this->eq($id_source)
681 .", ".$this->eq($document["nom"])
682 .", ".$this->eq($document["url"])
686 catch(Exception $e) { return false; }
687 return $sgbd->insert_id();
690 function del_source_documents($id_source)
691 { $sgbd = $this->sgbd();
693 $sql = "DELETE FROM #--sml_source_documents WHERE id_source=".$this->eq($id_source);
696 catch(Exception $e) { return false; }
700 # ----------------------------------------------------------------------------------------
701 # compositions de sources
704 function source_compositions($params)
705 { $id_source = isset($params["id_source"]) ? $params["id_source"] : null;
706 $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null;
707 $sgbd = $this->sgbd();
709 $compositions = array();
710 if(isset($id_source)){
712 $sql = "SELECT * FROM #--sml_source_compositions WHERE id_source=".$this->eq($id_source);
713 $rst = $sgbd->query($sql);
714 while($v_rst = $sgbd->fetch_assoc($rst))
715 { if(!isset($compositions[$v_rst["id_source"]])) $compositions[$v_rst["id_source"]] = array();
716 $compositions[$v_rst["id_source"]][] = $v_rst["id_composition"];
718 $sgbd->free_result($rst);
720 catch(Exception $e) { return false; }
721 return $compositions;
723 elseif(isset($id_composition))
724 { if($id_composition){
727 "SELECT * FROM #--sml_source_compositions WHERE id_composition=".$this->eq($id_composition);
728 $rst = $sgbd->query($sql);
729 while($v_rst = $sgbd->fetch_assoc($rst))
730 { if(!isset($compositions[$v_rst["id_composition"]])) $compositions[$v_rst["id_composition"]] = array();
731 $compositions[$v_rst["id_composition"]][] = $v_rst["id_source"];
733 $sgbd->free_result($rst);
735 catch(Exception $e) { return false; }
736 return $compositions;
741 "SELECT DISTINCT id_source FROM #--sml_source_compositions";
742 $rst = $sgbd->query($sql);
743 while($v_rst = $sgbd->fetch_assoc($rst)) $compositions[] = $v_rst["id_source"];
744 $sgbd->free_result($rst);
746 catch(Exception $e) { return false; }
747 return $compositions;
753 function set_source_composition($id_source, $id_composition){
754 $sgbd = $this->sgbd();
757 "INSERT INTO #--sml_source_compositions(id_source, id_composition) VALUES"
758 ."( ".$this->eq($id_source)
759 .", ".$this->eq($id_composition)
763 catch(Exception $e) { return false; }
764 return $this->set_source_xml($id_composition);
767 function del_source_compositions($params){
769 $id_source = isset($params["id_source"]) ? $params["id_source"] : null;
770 $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null;
771 $to_delete = array();
772 $to_update = array();
773 if(isset($id_composition)) $to_update[] = $id_composition;
774 $sgbd = $this->sgbd();
775 if(isset($id_source)){
777 $sql = "SELECT * FROM #--sml_source_compositions WHERE id_source=".$this->eq($id_source);
778 $rst = $sgbd->query($sql);
779 while($v_rst = $sgbd->fetch_assoc($rst)) $to_update[] = $v_rst["id_composition"];
780 $sgbd->free_result($rst);
782 catch(Exception $e) { return false; }
785 $sql = "DELETE FROM #--sml_source_compositions";
787 $WHERE .= (isset($id_source) ? ($WHERE ? " OR " : " WHERE ")."id_source=".$this->eq($id_source) : "");
788 $WHERE .= (isset($id_composition) ? ($WHERE ? " OR " : " WHERE ")."id_composition=".$this->eq($id_composition) : "");
792 catch(Exception $e) { return false; }
793 foreach($to_update as $id_source_xml){
794 if(!$this->set_source_xml($id_source_xml)) return false;
799 function has_sources($id_composition)
800 { $sgbd = $this->sgbd();
803 $sql = "SELECT count(*) as n FROM #--sml_source_compositions WHERE id_composition=".$this->eq($id_composition);
804 $rst = $sgbd->query($sql);
806 if($v_rst = $sgbd->fetch_assoc($rst)) $has_sources = $v_rst["n"];
807 $sgbd->free_result($rst);
809 catch(Exception $e) { return false; }
813 function source_ariane($id_source, $ariane = array())
814 { if(($compositions = $this->source_compositions(array("id_source" => $id_source))) !== false)
815 { if(isset($compositions[$id_source]) && $compositions[$id_source])
816 { foreach($compositions[$id_source] as $id_composition)
817 { if(($ariane = $this->source_ariane($id_composition, $ariane)) !== false)
818 { if(($ariane[$id_composition] = $this->source($id_composition)) !== false)
821 else $ariane = false;
823 else $ariane = false;
828 else $ariane = false;