marche avec MySql, SQLite ou XML
[mw_sourceml] / app / data / modules / sql / sml_data_source_groupes.php
index 44dec36..0ada4f0 100644 (file)
       return $sources;
     }
 
+    function source_has_groupe($id_source, $id_groupe){
+      $sgbd = $this->sgbd();
+      $HAS_THIS_GROUP = 0;
+      try{
+        $sql =
+         "SELECT count(*) as n FROM #--sml_sources_authors"
+        ." WHERE id_source=".$this->eq($id_source)
+        ." AND id_author=".$this->eq($id_groupe);
+        $rst = $sgbd->query($sql);
+        if($v_rst = $sgbd->fetch_assoc($rst)) $HAS_THIS_GROUP = $v_rst["n"];
+        $sgbd->free_result($rst);
+      }
+      catch(Exception $e) { $HAS_THIS_GROUP = false; }
+      return $HAS_THIS_GROUP;
+    }
+
     function add_source_groupe($id_source, $id_groupe, $id_groupe_status)
     { $sgbd = $this->sgbd();
       try{
       return true;
     }
 
-    function del_source_groupe($id)
-    { $sgbd = $this->sgbd();
+    function del_source_groupe($id_source, $id_author){
+      $sgbd = $this->sgbd();
       try{
-        $sql = "DELETE FROM #--sml_sources_authors WHERE id=".$this->eq($id);
+        $sql =
+         "DELETE FROM #--sml_sources_authors"
+        ." WHERE id_source=".$this->eq($id_source)
+        ." AND id_author=".$this->eq($id_author);
         $sgbd->query($sql);
       }
       catch(Exception $e) { return false; }
 
     function get_editor_groupes($groupes){
       $editor_groupes = array();
-      if(is_array($groupes)) foreach($groupes as $source_groupe)
-      { if(
+      if(is_array($groupes)) foreach($groupes as $source_groupe){
+        if(
               $source_groupe["id_groupe_status"] == $this->id_groupe_status_admin()
           ||  $source_groupe["id_groupe_status"] == $this->id_groupe_status_editeur()
         ){
       return $permissions;
     }
 
+// --------------------------------------------------------------------
+
+    function sources_invitations($groupes, $id_user){
+      $groupes_in = "";
+      foreach($groupes as $id_groupe => $groupe) $groupes_in .= ($groupes_in ? "," : "").$id_groupe;
+      return $this->list_sml_sources_invitations(
+        array(
+          "index_name" => "id",
+          "where"=> ($groupes_in ? "id_author IN(".$groupes_in.") OR " : "")."id_user=".$id_user,
+          "order_by" => "date_invitation",
+          "order" => "DESC"
+        )
+      );
+    }
+
   }
 
 ?>
\ No newline at end of file