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 $order_by = isset($params["order_by"]) ? $params["order_by"] : "ordre";
48 $order = isset($params["order"]) ? $params["order"] : "ASC";
49 $sgbd = $this->sgbd();
51 $ORDER_FIELD_EXISTS = false;
52 $ORDER_FROM_SOURCES_INFOS = !$ORDER_FIELD_EXISTS;
53 $sources = array("list" => array(), "total" => 0);
54 $COUNT_SELECT = "SELECT count(*) as n";
55 $SELECT = "SELECT #--sml_sources.*, #--sml_sources.id_class as `status`";
56 if($ORDER_FROM_SOURCES_INFOS){
57 if($order_by == "ordre"){
58 $SELECT .= ", (0 + #--sml_sources_infos.`value`) as ordre";
61 $SELECT .= ", #--sml_sources_infos.`value` as ".$this->eq($order_by, false);
64 $FROM = "#--sml_sources";
65 if(isset($id_user)) $FROM .= ", #--sml_authors, #--sml_sources_authors";
66 elseif(isset($id_groupe)) $FROM .= ", #--sml_sources_authors";
67 if(isset($id_source)) $FROM .= ", #--sml_source_compositions";
68 elseif(isset($id_composition) && $id_composition) $FROM .= ", #--sml_source_compositions";
69 if(isset($id_source_derivation)) $FROM .= ", #--sml_source_derivations";
70 $FROM = " FROM (".$FROM.")";
71 if($ORDER_FROM_SOURCES_INFOS){
73 " LEFT JOIN #--sml_sources_infos"
74 ." ON (#--sml_sources_infos.id_source=#--sml_sources.id AND #--sml_sources_infos.`key`=".$this->eq($order_by).")";
77 if(isset($id_user)) $WHERE .=
78 ($WHERE ? " AND " : " WHERE ")
79 ." #--sml_sources.id=#--sml_sources_authors.id_source"
80 ." AND #--sml_sources_authors.id_author=#--sml_authors.id"
81 ." AND #--sml_authors.id_user=".$this->eq($id_user)/*
82 ." AND #--sml_sources_authors.id_sources_access=".$this->id_groupe_status_admin()*/;
83 if(isset($id_groupe)) $WHERE .=
84 ($WHERE ? " AND " : " WHERE ")
85 ." #--sml_sources.id=#--sml_sources_authors.id_source"
86 ." AND #--sml_sources_authors.id_author=".$this->eq($id_groupe)/*
87 ." AND #--sml_sources_authors.id_sources_access=".$this->id_groupe_status_admin()*/;
88 if(isset($status)) $WHERE .=
89 ($WHERE ? " AND " : " WHERE ")
90 ." #--sml_sources.id_class=".$this->eq($status);
91 if(isset($id_source)) $WHERE .=
92 ($WHERE ? " AND " : " WHERE ")
93 ." #--sml_sources.id=#--sml_source_compositions.id_composition"
94 ." AND #--sml_source_compositions.id_source=".$this->eq($id_source);
95 elseif(isset($id_composition))
98 ($WHERE ? " AND " : " WHERE ")
99 ." #--sml_sources.id=#--sml_source_compositions.id_source"
100 ." AND #--sml_source_compositions.id_composition=".$this->eq($id_composition);
103 { if(($sources_ids = $this->source_compositions(array("id_composition" => ""))) !== false)
106 foreach($sources_ids as $in_source_id) $NOT_IN .= ($NOT_IN ? "," : "").$in_source_id;
107 $WHERE .= ($WHERE ? " AND " : " WHERE ")." #--sml_sources.id NOT IN(".$NOT_IN.")";
113 if(isset($id_source_derivation)) $WHERE .=
114 ($WHERE ? " AND " : " WHERE ")
115 ." #--sml_sources.id=#--sml_source_derivations.id_source"
116 ." AND #--sml_source_derivations.derivation=".$this->eq($this->source_xml_url($id_source_derivation));
117 if(isset($id_licence)) $WHERE .=
118 ($WHERE ? " AND " : " WHERE ")
119 ." #--sml_sources.licence=".$this->eq($id_licence);
120 $ORDER_BY = " ORDER BY ".$order_by." ".$order;
121 $LIMIT = (isset($start) && $env->config("max_list") ? " LIMIT ".$env->config("max_list")." OFFSET ".$start : "");
123 $sql = $COUNT_SELECT.$FROM.$WHERE;
124 $rst = $sgbd->query($sql);
125 if($v_rst = $sgbd->fetch_assoc($rst)) $sources["total"] = $v_rst["n"];
126 $sgbd->free_result($rst);
127 if($sources["total"])
128 { $sql = $SELECT.$FROM.$WHERE.$ORDER_BY.$LIMIT;
129 $rst = $sgbd->query($sql);
131 while($v_rst = $sgbd->fetch_assoc($rst)){
132 if(($sources["list"][$v_rst["id"]] = $this->load_source($v_rst)) === false){
137 $sgbd->free_result($rst);
138 if(!$OK) return false;
141 catch(Exception $e) { $sources = false; }
145 function source($id, $load = false){
146 $sgbd = $this->sgbd();
148 $sql = "SELECT #--sml_sources.*, #--sml_sources.id_class as status FROM #--sml_sources WHERE id=".$this->eq($id);
149 $rst = $sgbd->query($sql);
151 if($v_rst = $sgbd->fetch_assoc($rst)){
152 $source = $load ? $this->load_source($v_rst) : $this->get_source_from_v_rst($v_rst);
154 $sgbd->free_result($rst);
156 catch(Exception $e) { $source = false; }
160 function get_source_from_v_rst($v_rst){
161 $sgbd = $this->sgbd();
162 $source = $this->empty_source();
163 foreach($v_rst as $rst_key => $rst_value) $source[$rst_key] = $rst_value;
165 $si_sql = "SELECT * FROM #--sml_sources_infos WHERE id_source=".$this->eq($source["id"]);
166 $si_rst = $sgbd->query($si_sql);
167 while($v_si_rst = $sgbd->fetch_assoc($si_rst)){
168 if(!isset($source[$v_si_rst["key"]])) $source[$v_si_rst["key"]] = $v_si_rst["value"];
170 $sgbd->free_result($si_rst);
171 if($source["reference"]){
172 if(!is_array($source["reference"])){
173 $reference_url = $source["reference"];
174 $source["reference"] = $this->empty_source();
175 $source["reference"]["xml"]["url"] = $reference_url;
179 if(!is_array($source["licence"])){
180 $source["licence"] = array(
181 "id" => $source["licence"]
186 catch(Exception $e) { $source = false; }
190 function load_source($source){
192 if(!isset($source["id"])) return false;
193 $source = $this->get_source_from_v_rst($source);
194 $source["xml"] = array
195 ( "url" => $this->source_xml_url($source["id"]),
196 "content" => $this->get_source_xml($source["id"])
198 $source["documents"] = array();
199 if(($source["groupes"] = $this->source_groupes($source["id"])) === false) return false;
200 $source["image_uri"] =
201 ( isset($source["image"]) && $source["image"] ?
202 $env->path("content")."uploads/".$source["image"]
205 if(($source["has_sources"] = $this->has_sources($source["id"])) === false) return false;
206 if(($source["has_derivations"] = $this->source_derivations(array("derivation" => $source["id"]))) === false) return false;
207 if(($source["derivations"] = $this->source_derivations(array("id_source" => $source["id"]))) === false) return false;
208 if(($source["reference"] = $this->source_reference($source)) === false) return false;
209 if(!$source["reference"])
210 { if(($source["documents"] = $this->source_documents($source["id"])) === false) return false;
220 $documents = array(),
221 $reference = array(),
222 $derivations = array(),
225 { $sgbd = $this->sgbd();
227 ( "groupes" => $groupes,
228 "titre" => $reference ? null : $titre,
230 "licence" => $reference ? null : $licence,
231 "reference" => $reference ? $reference : null,
232 "date_creation" => isset($infos["date_creation"]) ? $infos["date_creation"] : null,
233 "date_inscription" => isset($infos["date_inscription"]) ? $infos["date_inscription"] : date("Y-m-d")
237 "INSERT INTO #--sml_sources(id_class, reference, titre, licence, date_creation, date_inscription)"
239 ."( ".$this->eq($source["status"])
240 .", ".$this->eq($source["reference"] ? $source["reference"]["xml"]["url"] : null)
241 .", ".$this->eq($source["titre"])
242 .", ".$this->eq($source["licence"])
243 .", ".$this->eq($source["date_creation"])
244 .", ".$this->eq($source["date_inscription"])
247 $id = $sgbd->insert_id();
248 foreach($source["groupes"] as $id_groupe => $groupe)
249 { if($groupe["id"] && $groupe["id_groupe_status"])
250 { if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false;
254 if(isset($infos["date_creation"])) unset($infos["date_creation"]);
255 if(isset($infos["date_inscription"])) unset($infos["date_inscription"]);
256 foreach($infos as $key => $value){
258 "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
261 .", ".$this->eq($key)
262 .", ".$this->eq($value)
267 catch(Exception $e) { return false; }
268 foreach($derivations as $source_derivation)
270 ( ( $id_source_derivation = $this->add_source_derivation
272 $source_derivation["xml"]["url"],
273 $source_derivation["xml"]["use_edit_content"] ? $source_derivation["xml"]["content"] : ""
281 { if($reference["xml"]["use_edit_content"])
282 { if(!$this->set_edit_reference_content($id, $reference["xml"]["content"]))
288 { foreach($documents as $document)
289 { if(!$this->add_source_document($id, $document)) return false;
292 if(!$this->set_source_xml($id)) return false;
302 $documents = array(),
303 $reference = array(),
304 $derivations = array(),
307 { if($source = $this->source($id))
308 { $sgbd = $this->sgbd();
310 ( "groupes" => $groupes,
311 "titre" => $reference ? null : $titre,
312 "licence" => $reference ? null : $licence,
313 "reference" => $reference ? $reference : null,
314 "date_creation" => isset($infos["date_creation"]) ? $infos["date_creation"] : null
318 "UPDATE #--sml_sources SET"
319 ." reference=".$this->eq($source["reference"] ? $source["reference"]["xml"]["url"] : null)
320 .", titre=".$this->eq($source["titre"])
321 .", licence=".$this->eq($source["licence"])
322 .", date_creation=".$this->eq($source["date_creation"])
323 ." WHERE id=".$this->eq($id);
325 if(!$this->del_source_groupes($id)) return false;
326 foreach($source["groupes"] as $id_groupe => $groupe)
327 { if($groupe["id"] && $groupe["id_groupe_status"]){
328 if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false;
332 $sql = "DELETE FROM #--sml_sources_infos WHERE id_source=".$this->eq($id);
334 if(isset($infos["date_creation"])) unset($infos["date_creation"]);
335 if(isset($infos["date_inscription"])) unset($infos["date_inscription"]);
336 foreach($infos as $key => $value)
338 "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
341 .", ".$this->eq($key)
342 .", ".$this->eq($value)
347 catch(Exception $e) { return false; }
348 if(!$this->del_source_derivations($id)) return false;
349 if(!$this->del_edit_reference_content($id)) return false;
350 if(!$this->del_source_documents($id)) return false;
351 foreach($derivations as $source_derivation)
353 ( ( $id_source_derivation = $this->add_source_derivation
355 $source_derivation["xml"]["url"],
356 $source_derivation["xml"]["use_edit_content"] ? $source_derivation["xml"]["content"] : ""
364 { if($reference["xml"]["use_edit_content"])
365 { if(!$this->set_edit_reference_content($id, $reference["xml"]["content"]))
371 foreach($documents as $document){
372 if(!$this->add_source_document($id, $document)) return false;
375 if(!$this->set_source_xml($id)) return false;
381 function set_source_info($id_source, $key, $value){
382 $sgbd = $this->sgbd();
385 "SELECT id FROM #--sml_sources_infos"
386 ." WHERE id_source=".$this->eq($id_source)
387 ." AND `key`=".$this->eq($key);
388 $rst = $sgbd->query($sql);
390 if($v_rst = $sgbd->fetch_assoc($rst)) $id = $v_rst["id"];
391 $sgbd->free_result($rst);
392 if(isset($id)) $sql =
393 "UPDATE #--sml_sources_infos SET"
394 ." `value`=".$this->eq($value)
395 ." WHERE id=".$this->eq($id);
397 "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
399 ."( ".$this->eq($id_source)
400 .", ".$this->eq($key)
401 .", ".$this->eq($value)
404 if(!isset($id)) $id = $sgbd->insert_id();
406 catch(Exception $e) { return false; }
410 function del_source($id){
411 $sgbd = $this->sgbd();
412 if(!$this->del_source_compositions(array("id_source" => $id, "id_composition" => $id))) return false;
413 if(!$this->del_edit_reference_content($id)) return false;
414 if(!$this->del_source_derivations($id)) return false;
415 if(!$this->del_source_xml($id)) return false;
416 if(!$this->del_source_documents($id)) return false;
417 if(!$this->del_source_groupes($id)) return false;
419 $sql = "DELETE FROM #--sml_sources_infos WHERE id_source=".$this->eq($id);
421 $sql = "DELETE FROM #--sml_sources WHERE id=".$this->eq($id);
424 catch(Exception $e) { return false; }
428 # ----------------------------------------------------------------------------------------
429 # derivations de sources
432 function init_source_derivations()
433 { $sgbd = $this->sgbd();
434 $rst = $sgbd->table_exists("#--sml_source_derivations");
442 ."(table_prefix)source_derivations :\n"
444 ." id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,\n"
445 ." id_source INT NOT NULL,\n"
446 ." derivation VARCHAR NOT NULL\n"
451 else return "impossible de chercher la table #--sml_source_derivations";
455 function source_derivations($params)
456 { $sgbd = $this->sgbd();
458 $derivations = array();
459 // sources dont "id_source" est une derivation
460 if(isset($params["id_source"])){
464 ." FROM #--sml_source_derivations"
465 ." WHERE #--sml_source_derivations.id_source=".$this->eq($params["id_source"]);
466 $rst = $sgbd->query($sql);
467 while($v_rst = $sgbd->fetch_assoc($rst))
468 { $derivations[$v_rst["id"]] = array();
469 $derivation_edit_file = $this->derivation_edit_xml_path($v_rst["id_source"], $v_rst["id"]);
470 if(file_exists($derivation_edit_file))
471 { if(($derivation_edit_content = $this->get_edit_derivation_content($v_rst["id_source"], $v_rst["id"])) !== false)
472 { if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"], $derivation_edit_content)) !==false)
473 { $derivations[$v_rst["id"]]["xml"] = array
474 ( "url" => $v_rst["derivation"],
475 "content" => $derivation_edit_content,
476 "use_edit_content" => true
484 { if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"])) !==false)
485 { $derivations[$v_rst["id"]]["id_source"] = $v_rst["id_source"];
487 else $derivations[$v_rst["id"]] = $this->empty_source();
489 $derivations[$v_rst["id"]]["id_source"] = $v_rst["id_source"];
491 $sgbd->free_result($rst);
493 catch(Exception $e) { return false; }
496 // sources qui derivent de "derivation"
497 elseif(isset($params["derivation"]))
498 { $source_xml_url = $params["derivation"];
499 if(preg_match("/^[0-9]+$/", $source_xml_url)) $source_xml_url = $this->source_xml_url($source_xml_url);
502 "SELECT #--sml_sources.*"
503 ." FROM #--sml_sources, #--sml_source_derivations"
504 ." WHERE #--sml_sources.id=#--sml_source_derivations.id_source"
505 ." AND #--sml_source_derivations.derivation=".$this->eq($source_xml_url);
506 $rst = $sgbd->query($sql);
507 if(!isset($rst)) return false;
508 while($v_rst = $sgbd->fetch_assoc($rst)) $derivations[$v_rst["id"]] = $v_rst;
509 $sgbd->free_result($rst);
511 catch(Exception $e) { return false; }
517 function source_derivation($id){
518 $sgbd = $this->sgbd();
520 $derivation = array();
524 ." FROM #--sml_source_derivations"
525 ." WHERE #--sml_source_derivations.id=".$this->eq($id);
526 $rst = $sgbd->query($sql);
527 if($v_rst = $sgbd->fetch_assoc($rst)) $derivation = $v_rst;
528 $sgbd->free_result($rst);
530 catch(Exception $e) { return false; }
534 function add_source_derivation($id_source, $derivation, $edit_content = "")
535 { $sgbd = $this->sgbd();
538 "INSERT INTO #--sml_source_derivations(id_source, derivation)"
540 ."( ".$this->eq($id_source)
541 .", ".$this->eq($derivation)
544 $id_source_derivation = $sgbd->insert_id();
546 catch(Exception $e) { return false; }
548 { if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content))
552 return $id_source_derivation;
555 function set_source_derivation($id_source_derivation, $id_source, $derivation, $edit_content = "")
556 { $sgbd = $this->sgbd();
559 "UPDATE #--sml_source_derivations SET"
560 ." id_source=".$this->eq($id_source)
561 .", derivation=".$this->eq($derivation)
562 ." WHERE id=".$this->eq($id_source_derivation);
565 catch(Exception $e) { return false; }
567 { if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content))
574 function del_source_derivation($id_source_derivation)
575 { if(($derivation = $this->source_derivation($id_source_derivation)) !== false)
576 { if(($derivations = $this->source_derivations(array("id_source" => $derivation["id_source"]))) !== false)
577 { $sgbd = $this->sgbd();
579 $sql = "DELETE FROM #--sml_source_derivations WHERE id=".$this->eq($id_source_derivation);
582 catch(Exception $e) { return false; }
583 if(count($derivations) > 1)
584 { return $this->del_edit_derivation_content($derivation["id_source"], $id_source_derivation);
586 else return $this->del_edit_derivations($derivation["id_source"]);
592 function del_source_derivations($id_source)
593 { $sgbd = $this->sgbd();
595 $sql = "DELETE FROM #--sml_source_derivations WHERE id_source=".$this->eq($id_source);
598 catch(Exception $e) { return false; }
599 return $this->del_edit_derivations($id_source);
602 # ----------------------------------------------------------------------------------------
606 function source_reference($source)
607 { $reference = array();
608 if($source["reference"])
609 { if(!is_array($source["reference"]))
610 { $source["reference"] = array
611 ( "url" => $source["reference"],
613 "use_edit_content" => false
616 $reference_edit_file = $this->reference_edit_xml_path($source["id"]);
617 if(file_exists($reference_edit_file))
618 { if(($reference_edit_content = $this->get_edit_reference_content($source["id"])) !== false)
619 { if(($reference = $this->source_xml_read($source["reference"], $reference_edit_content)) !==false)
620 { $reference["xml"] = array
621 ( "url" => $source["reference"]["xml"]["url"],
622 "content" => $reference_edit_content,
623 "use_edit_content" => true
631 { if(($reference = $this->source_xml_read($source["reference"]["xml"]["url"])) ===false)
632 { $reference = $this->empty_source();
639 # ----------------------------------------------------------------------------------------
643 function source_documents($id_source)
644 { $sgbd = $this->sgbd();
645 $documents = array();
647 $sql = "SELECT * FROM #--sml_source_documents WHERE id_source=".$this->eq($id_source);
648 $rst = $sgbd->query($sql);
649 if(!isset($rst)) return false;
650 while($v_rst = $sgbd->fetch_assoc($rst)) $documents[$v_rst["id"]] = $v_rst;
651 $sgbd->free_result($rst);
653 catch(Exception $e) { return false; }
657 function add_source_document($id_source, $document)
658 { $sgbd = $this->sgbd();
661 "INSERT INTO #--sml_source_documents(id_source, nom, url)"
663 ."( ".$this->eq($id_source)
664 .", ".$this->eq($document["nom"])
665 .", ".$this->eq($document["url"])
669 catch(Exception $e) { return false; }
670 return $sgbd->insert_id();
673 function del_source_documents($id_source)
674 { $sgbd = $this->sgbd();
676 $sql = "DELETE FROM #--sml_source_documents WHERE id_source=".$this->eq($id_source);
679 catch(Exception $e) { return false; }
683 # ----------------------------------------------------------------------------------------
684 # compositions de sources
687 function source_compositions($params)
688 { $id_source = isset($params["id_source"]) ? $params["id_source"] : null;
689 $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null;
690 $sgbd = $this->sgbd();
692 $compositions = array();
693 if(isset($id_source)){
695 $sql = "SELECT * FROM #--sml_source_compositions WHERE id_source=".$this->eq($id_source);
696 $rst = $sgbd->query($sql);
697 while($v_rst = $sgbd->fetch_assoc($rst))
698 { if(!isset($compositions[$v_rst["id_source"]])) $compositions[$v_rst["id_source"]] = array();
699 $compositions[$v_rst["id_source"]][] = $v_rst["id_composition"];
701 $sgbd->free_result($rst);
703 catch(Exception $e) { return false; }
704 return $compositions;
706 elseif(isset($id_composition))
707 { if($id_composition){
710 "SELECT * FROM #--sml_source_compositions WHERE id_composition=".$this->eq($id_composition);
711 $rst = $sgbd->query($sql);
712 while($v_rst = $sgbd->fetch_assoc($rst))
713 { if(!isset($compositions[$v_rst["id_composition"]])) $compositions[$v_rst["id_composition"]] = array();
714 $compositions[$v_rst["id_composition"]][] = $v_rst["id_source"];
716 $sgbd->free_result($rst);
718 catch(Exception $e) { return false; }
719 return $compositions;
724 "SELECT DISTINCT id_source FROM #--sml_source_compositions";
725 $rst = $sgbd->query($sql);
726 while($v_rst = $sgbd->fetch_assoc($rst)) $compositions[] = $v_rst["id_source"];
727 $sgbd->free_result($rst);
729 catch(Exception $e) { return false; }
730 return $compositions;
736 function set_source_composition($id_source, $id_composition){
737 $sgbd = $this->sgbd();
740 "INSERT INTO #--sml_source_compositions(id_source, id_composition) VALUES"
741 ."( ".$this->eq($id_source)
742 .", ".$this->eq($id_composition)
746 catch(Exception $e) { return false; }
747 return $this->set_source_xml($id_composition);
750 function del_source_compositions($params){
752 $id_source = isset($params["id_source"]) ? $params["id_source"] : null;
753 $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null;
754 $to_delete = array();
755 $to_update = array();
756 if(isset($id_composition)) $to_update[] = $id_composition;
757 $sgbd = $this->sgbd();
758 if(isset($id_source)){
760 $sql = "SELECT * FROM #--sml_source_compositions WHERE id_source=".$this->eq($id_source);
761 $rst = $sgbd->query($sql);
762 while($v_rst = $sgbd->fetch_assoc($rst)) $to_update[] = $v_rst["id_composition"];
763 $sgbd->free_result($rst);
765 catch(Exception $e) { return false; }
768 $sql = "DELETE FROM #--sml_source_compositions";
770 $WHERE .= (isset($id_source) ? ($WHERE ? " OR " : " WHERE ")."id_source=".$this->eq($id_source) : "");
771 $WHERE .= (isset($id_composition) ? ($WHERE ? " OR " : " WHERE ")."id_composition=".$this->eq($id_composition) : "");
775 catch(Exception $e) { return false; }
776 foreach($to_update as $id_source_xml){
777 if(!$this->set_source_xml($id_source_xml)) return false;
782 function has_sources($id_composition)
783 { $sgbd = $this->sgbd();
786 $sql = "SELECT count(*) as n FROM #--sml_source_compositions WHERE id_composition=".$this->eq($id_composition);
787 $rst = $sgbd->query($sql);
789 if($v_rst = $sgbd->fetch_assoc($rst)) $has_sources = $v_rst["n"];
790 $sgbd->free_result($rst);
792 catch(Exception $e) { return false; }
796 function source_ariane($id_source, $ariane = array())
797 { if(($compositions = $this->source_compositions(array("id_source" => $id_source))) !== false)
798 { if(isset($compositions[$id_source]) && $compositions[$id_source])
799 { foreach($compositions[$id_source] as $id_composition)
800 { if(($ariane = $this->source_ariane($id_composition, $ariane)) !== false)
801 { if(($ariane[$id_composition] = $this->source($id_composition)) !== false)
804 else $ariane = false;
806 else $ariane = false;
811 else $ariane = false;