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($user = $env->user()){
210 if(($source["permissions"] = $this->source_permissions($source, $user["id"])) === false) return false;
212 if(!$source["reference"])
213 { if(($source["documents"] = $this->source_documents($source["id"])) === false) return false;
223 $documents = array(),
224 $reference = array(),
225 $derivations = array(),
228 { $sgbd = $this->sgbd();
230 ( "groupes" => $groupes,
231 "titre" => $reference ? null : $titre,
233 "licence" => $reference ? null : $licence,
234 "reference" => $reference ? $reference : null,
235 "date_creation" => isset($infos["date_creation"]) ? $infos["date_creation"] : null,
236 "date_inscription" => isset($infos["date_inscription"]) ? $infos["date_inscription"] : date("Y-m-d")
240 "INSERT INTO #--sml_sources(id_class, reference, titre, licence, date_creation, date_inscription)"
242 ."( ".$this->eq($source["status"])
243 .", ".$this->eq($source["reference"] ? $source["reference"]["xml"]["url"] : null)
244 .", ".$this->eq($source["titre"])
245 .", ".$this->eq($source["licence"])
246 .", ".$this->eq($source["date_creation"])
247 .", ".$this->eq($source["date_inscription"])
250 $id = $sgbd->insert_id();
251 foreach($source["groupes"] as $id_groupe => $groupe)
252 { if($groupe["id"] && $groupe["id_groupe_status"])
253 { if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false;
257 if(isset($infos["date_creation"])) unset($infos["date_creation"]);
258 if(isset($infos["date_inscription"])) unset($infos["date_inscription"]);
259 foreach($infos as $key => $value){
261 "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
264 .", ".$this->eq($key)
265 .", ".$this->eq($value)
270 catch(Exception $e) { return false; }
271 foreach($derivations as $source_derivation)
273 ( ( $id_source_derivation = $this->add_source_derivation
275 $source_derivation["xml"]["url"],
276 $source_derivation["xml"]["use_edit_content"] ? $source_derivation["xml"]["content"] : ""
284 { if($reference["xml"]["use_edit_content"])
285 { if(!$this->set_edit_reference_content($id, $reference["xml"]["content"]))
291 { foreach($documents as $document)
292 { if(!$this->add_source_document($id, $document)) return false;
295 if(!$this->set_source_xml($id)) return false;
305 $documents = array(),
306 $reference = array(),
307 $derivations = array(),
310 { if($source = $this->source($id))
311 { $sgbd = $this->sgbd();
313 ( "groupes" => $groupes,
314 "titre" => $reference ? null : $titre,
315 "licence" => $reference ? null : $licence,
316 "reference" => $reference ? $reference : null,
317 "date_creation" => isset($infos["date_creation"]) ? $infos["date_creation"] : null
321 "UPDATE #--sml_sources SET"
322 ." reference=".$this->eq($source["reference"] ? $source["reference"]["xml"]["url"] : null)
323 .", titre=".$this->eq($source["titre"])
324 .", licence=".$this->eq($source["licence"])
325 .", date_creation=".$this->eq($source["date_creation"])
326 ." WHERE id=".$this->eq($id);
328 if(!$this->del_source_groupes($id)) return false;
329 foreach($source["groupes"] as $id_groupe => $groupe)
330 { if($groupe["id"] && $groupe["id_groupe_status"]){
331 if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false;
335 $sql = "DELETE FROM #--sml_sources_infos WHERE id_source=".$this->eq($id);
337 if(isset($infos["date_creation"])) unset($infos["date_creation"]);
338 if(isset($infos["date_inscription"])) unset($infos["date_inscription"]);
339 foreach($infos as $key => $value)
341 "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
344 .", ".$this->eq($key)
345 .", ".$this->eq($value)
350 catch(Exception $e) { return false; }
351 if(!$this->del_source_derivations($id)) return false;
352 if(!$this->del_edit_reference_content($id)) return false;
353 if(!$this->del_source_documents($id)) return false;
354 foreach($derivations as $source_derivation)
356 ( ( $id_source_derivation = $this->add_source_derivation
358 $source_derivation["xml"]["url"],
359 $source_derivation["xml"]["use_edit_content"] ? $source_derivation["xml"]["content"] : ""
367 { if($reference["xml"]["use_edit_content"])
368 { if(!$this->set_edit_reference_content($id, $reference["xml"]["content"]))
374 foreach($documents as $document){
375 if(!$this->add_source_document($id, $document)) return false;
378 if(!$this->set_source_xml($id)) return false;
384 function set_source_info($id_source, $key, $value){
385 $sgbd = $this->sgbd();
388 "SELECT id FROM #--sml_sources_infos"
389 ." WHERE id_source=".$this->eq($id_source)
390 ." AND `key`=".$this->eq($key);
391 $rst = $sgbd->query($sql);
393 if($v_rst = $sgbd->fetch_assoc($rst)) $id = $v_rst["id"];
394 $sgbd->free_result($rst);
395 if(isset($id)) $sql =
396 "UPDATE #--sml_sources_infos SET"
397 ." `value`=".$this->eq($value)
398 ." WHERE id=".$this->eq($id);
400 "INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
402 ."( ".$this->eq($id_source)
403 .", ".$this->eq($key)
404 .", ".$this->eq($value)
407 if(!isset($id)) $id = $sgbd->insert_id();
409 catch(Exception $e) { return false; }
413 function del_source($id){
414 $sgbd = $this->sgbd();
415 if(!$this->del_source_compositions(array("id_source" => $id, "id_composition" => $id))) return false;
416 if(!$this->del_edit_reference_content($id)) return false;
417 if(!$this->del_source_derivations($id)) return false;
418 if(!$this->del_source_xml($id)) return false;
419 if(!$this->del_source_documents($id)) return false;
420 if(!$this->del_source_groupes($id)) return false;
422 $sql = "DELETE FROM #--sml_sources_infos WHERE id_source=".$this->eq($id);
424 $sql = "DELETE FROM #--sml_sources WHERE id=".$this->eq($id);
427 catch(Exception $e) { return false; }
431 # ----------------------------------------------------------------------------------------
432 # derivations de sources
435 function init_source_derivations()
436 { $sgbd = $this->sgbd();
437 $rst = $sgbd->table_exists("#--sml_source_derivations");
445 ."(table_prefix)source_derivations :\n"
447 ." id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,\n"
448 ." id_source INT NOT NULL,\n"
449 ." derivation VARCHAR NOT NULL\n"
454 else return "impossible de chercher la table #--sml_source_derivations";
458 function source_derivations($params)
459 { $sgbd = $this->sgbd();
461 $derivations = array();
462 // sources dont "id_source" est une derivation
463 if(isset($params["id_source"])){
467 ." FROM #--sml_source_derivations"
468 ." WHERE #--sml_source_derivations.id_source=".$this->eq($params["id_source"]);
469 $rst = $sgbd->query($sql);
470 while($v_rst = $sgbd->fetch_assoc($rst))
471 { $derivations[$v_rst["id"]] = array();
472 $derivation_edit_file = $this->derivation_edit_xml_path($v_rst["id_source"], $v_rst["id"]);
473 if(file_exists($derivation_edit_file))
474 { if(($derivation_edit_content = $this->get_edit_derivation_content($v_rst["id_source"], $v_rst["id"])) !== false)
475 { if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"], $derivation_edit_content)) !==false)
476 { $derivations[$v_rst["id"]]["xml"] = array
477 ( "url" => $v_rst["derivation"],
478 "content" => $derivation_edit_content,
479 "use_edit_content" => true
487 { if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"])) !==false)
488 { $derivations[$v_rst["id"]]["id_source"] = $v_rst["id_source"];
490 else $derivations[$v_rst["id"]] = $this->empty_source();
492 $derivations[$v_rst["id"]]["id_source"] = $v_rst["id_source"];
494 $sgbd->free_result($rst);
496 catch(Exception $e) { return false; }
499 // sources qui derivent de "derivation"
500 elseif(isset($params["derivation"]))
501 { $source_xml_url = $params["derivation"];
502 if(preg_match("/^[0-9]+$/", $source_xml_url)) $source_xml_url = $this->source_xml_url($source_xml_url);
505 "SELECT #--sml_sources.*"
506 ." FROM #--sml_sources, #--sml_source_derivations"
507 ." WHERE #--sml_sources.id=#--sml_source_derivations.id_source"
508 ." AND #--sml_source_derivations.derivation=".$this->eq($source_xml_url);
509 $rst = $sgbd->query($sql);
510 if(!isset($rst)) return false;
511 while($v_rst = $sgbd->fetch_assoc($rst)) $derivations[$v_rst["id"]] = $v_rst;
512 $sgbd->free_result($rst);
514 catch(Exception $e) { return false; }
520 function source_derivation($id){
521 $sgbd = $this->sgbd();
523 $derivation = array();
527 ." FROM #--sml_source_derivations"
528 ." WHERE #--sml_source_derivations.id=".$this->eq($id);
529 $rst = $sgbd->query($sql);
530 if($v_rst = $sgbd->fetch_assoc($rst)) $derivation = $v_rst;
531 $sgbd->free_result($rst);
533 catch(Exception $e) { return false; }
537 function add_source_derivation($id_source, $derivation, $edit_content = "")
538 { $sgbd = $this->sgbd();
541 "INSERT INTO #--sml_source_derivations(id_source, derivation)"
543 ."( ".$this->eq($id_source)
544 .", ".$this->eq($derivation)
547 $id_source_derivation = $sgbd->insert_id();
549 catch(Exception $e) { return false; }
551 { if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content))
555 return $id_source_derivation;
558 function set_source_derivation($id_source_derivation, $id_source, $derivation, $edit_content = "")
559 { $sgbd = $this->sgbd();
562 "UPDATE #--sml_source_derivations SET"
563 ." id_source=".$this->eq($id_source)
564 .", derivation=".$this->eq($derivation)
565 ." WHERE id=".$this->eq($id_source_derivation);
568 catch(Exception $e) { return false; }
570 { if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content))
577 function del_source_derivation($id_source_derivation)
578 { if(($derivation = $this->source_derivation($id_source_derivation)) !== false)
579 { if(($derivations = $this->source_derivations(array("id_source" => $derivation["id_source"]))) !== false)
580 { $sgbd = $this->sgbd();
582 $sql = "DELETE FROM #--sml_source_derivations WHERE id=".$this->eq($id_source_derivation);
585 catch(Exception $e) { return false; }
586 if(count($derivations) > 1)
587 { return $this->del_edit_derivation_content($derivation["id_source"], $id_source_derivation);
589 else return $this->del_edit_derivations($derivation["id_source"]);
595 function del_source_derivations($id_source)
596 { $sgbd = $this->sgbd();
598 $sql = "DELETE FROM #--sml_source_derivations WHERE id_source=".$this->eq($id_source);
601 catch(Exception $e) { return false; }
602 return $this->del_edit_derivations($id_source);
605 # ----------------------------------------------------------------------------------------
609 function source_reference($source)
610 { $reference = array();
611 if($source["reference"])
612 { if(!is_array($source["reference"]))
613 { $source["reference"] = array
614 ( "url" => $source["reference"],
616 "use_edit_content" => false
619 $reference_edit_file = $this->reference_edit_xml_path($source["id"]);
620 if(file_exists($reference_edit_file))
621 { if(($reference_edit_content = $this->get_edit_reference_content($source["id"])) !== false)
622 { if(($reference = $this->source_xml_read($source["reference"], $reference_edit_content)) !==false)
623 { $reference["xml"] = array
624 ( "url" => $source["reference"]["xml"]["url"],
625 "content" => $reference_edit_content,
626 "use_edit_content" => true
634 { if(($reference = $this->source_xml_read($source["reference"]["xml"]["url"])) ===false)
635 { $reference = $this->empty_source();
642 # ----------------------------------------------------------------------------------------
646 function source_documents($id_source)
647 { $sgbd = $this->sgbd();
648 $documents = array();
650 $sql = "SELECT * FROM #--sml_source_documents WHERE id_source=".$this->eq($id_source);
651 $rst = $sgbd->query($sql);
652 if(!isset($rst)) return false;
653 while($v_rst = $sgbd->fetch_assoc($rst)) $documents[$v_rst["id"]] = $v_rst;
654 $sgbd->free_result($rst);
656 catch(Exception $e) { return false; }
660 function add_source_document($id_source, $document)
661 { $sgbd = $this->sgbd();
664 "INSERT INTO #--sml_source_documents(id_source, nom, url)"
666 ."( ".$this->eq($id_source)
667 .", ".$this->eq($document["nom"])
668 .", ".$this->eq($document["url"])
672 catch(Exception $e) { return false; }
673 return $sgbd->insert_id();
676 function del_source_documents($id_source)
677 { $sgbd = $this->sgbd();
679 $sql = "DELETE FROM #--sml_source_documents WHERE id_source=".$this->eq($id_source);
682 catch(Exception $e) { return false; }
686 # ----------------------------------------------------------------------------------------
687 # compositions de sources
690 function source_compositions($params)
691 { $id_source = isset($params["id_source"]) ? $params["id_source"] : null;
692 $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null;
693 $sgbd = $this->sgbd();
695 $compositions = array();
696 if(isset($id_source)){
698 $sql = "SELECT * FROM #--sml_source_compositions WHERE id_source=".$this->eq($id_source);
699 $rst = $sgbd->query($sql);
700 while($v_rst = $sgbd->fetch_assoc($rst))
701 { if(!isset($compositions[$v_rst["id_source"]])) $compositions[$v_rst["id_source"]] = array();
702 $compositions[$v_rst["id_source"]][] = $v_rst["id_composition"];
704 $sgbd->free_result($rst);
706 catch(Exception $e) { return false; }
707 return $compositions;
709 elseif(isset($id_composition))
710 { if($id_composition){
713 "SELECT * FROM #--sml_source_compositions WHERE id_composition=".$this->eq($id_composition);
714 $rst = $sgbd->query($sql);
715 while($v_rst = $sgbd->fetch_assoc($rst))
716 { if(!isset($compositions[$v_rst["id_composition"]])) $compositions[$v_rst["id_composition"]] = array();
717 $compositions[$v_rst["id_composition"]][] = $v_rst["id_source"];
719 $sgbd->free_result($rst);
721 catch(Exception $e) { return false; }
722 return $compositions;
727 "SELECT DISTINCT id_source FROM #--sml_source_compositions";
728 $rst = $sgbd->query($sql);
729 while($v_rst = $sgbd->fetch_assoc($rst)) $compositions[] = $v_rst["id_source"];
730 $sgbd->free_result($rst);
732 catch(Exception $e) { return false; }
733 return $compositions;
739 function set_source_composition($id_source, $id_composition){
740 $sgbd = $this->sgbd();
743 "INSERT INTO #--sml_source_compositions(id_source, id_composition) VALUES"
744 ."( ".$this->eq($id_source)
745 .", ".$this->eq($id_composition)
749 catch(Exception $e) { return false; }
750 return $this->set_source_xml($id_composition);
753 function del_source_compositions($params){
755 $id_source = isset($params["id_source"]) ? $params["id_source"] : null;
756 $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null;
757 $to_delete = array();
758 $to_update = array();
759 if(isset($id_composition)) $to_update[] = $id_composition;
760 $sgbd = $this->sgbd();
761 if(isset($id_source)){
763 $sql = "SELECT * FROM #--sml_source_compositions WHERE id_source=".$this->eq($id_source);
764 $rst = $sgbd->query($sql);
765 while($v_rst = $sgbd->fetch_assoc($rst)) $to_update[] = $v_rst["id_composition"];
766 $sgbd->free_result($rst);
768 catch(Exception $e) { return false; }
771 $sql = "DELETE FROM #--sml_source_compositions";
773 $WHERE .= (isset($id_source) ? ($WHERE ? " OR " : " WHERE ")."id_source=".$this->eq($id_source) : "");
774 $WHERE .= (isset($id_composition) ? ($WHERE ? " OR " : " WHERE ")."id_composition=".$this->eq($id_composition) : "");
778 catch(Exception $e) { return false; }
779 foreach($to_update as $id_source_xml){
780 if(!$this->set_source_xml($id_source_xml)) return false;
785 function has_sources($id_composition)
786 { $sgbd = $this->sgbd();
789 $sql = "SELECT count(*) as n FROM #--sml_source_compositions WHERE id_composition=".$this->eq($id_composition);
790 $rst = $sgbd->query($sql);
792 if($v_rst = $sgbd->fetch_assoc($rst)) $has_sources = $v_rst["n"];
793 $sgbd->free_result($rst);
795 catch(Exception $e) { return false; }
799 function source_ariane($id_source, $ariane = array())
800 { if(($compositions = $this->source_compositions(array("id_source" => $id_source))) !== false)
801 { if(isset($compositions[$id_source]) && $compositions[$id_source])
802 { foreach($compositions[$id_source] as $id_composition)
803 { if(($ariane = $this->source_ariane($id_composition, $ariane)) !== false)
804 { if(($ariane[$id_composition] = $this->source($id_composition)) !== false)
807 else $ariane = false;
809 else $ariane = false;
814 else $ariane = false;