]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Possibilità di vedere le persone di un certo ufficio.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Tue, 4 Dec 2012 09:27:35 +0000 (10:27 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Tue, 4 Dec 2012 09:27:35 +0000 (10:27 +0100)
src/main.c
src/persone.c
src/persone.h

index d025800c7970cf5c373b138c630c44a015564691..01f01021a6640084a8727c0100197d0257e61b70 100644 (file)
@@ -107,7 +107,7 @@ on_mnu_view_persone_activate (GtkMenuItem *menuitem,
 {
        GtkWidget *vbx;
 
-       OrganigrammaPersone *m = organigramma_persone_new (commons, FALSE);
+       OrganigrammaPersone *m = organigramma_persone_new (commons, FALSE, 0, NULL);
 
        vbx = organigramma_persone_get_widget (m);
 
index 361d471ee0ca38f5d74e8e982cfb815d1179b874..a5c149510c9af76a3fb872df38f8dd6b6d1053c7 100644 (file)
@@ -74,6 +74,9 @@ struct _OrganigrammaPersonePrivate
                GtkListStore *lstore_persone;
 
                gboolean selezione;
+               guint id_uffici;
+               GDateTime *when;
+
                GtkWindow *wtransient;
        };
 
@@ -119,7 +122,8 @@ organigramma_persone_init (OrganigrammaPersone *persone)
  * Returns: the newly created #OrganigrammaPersone object.
  */
 OrganigrammaPersone
-*organigramma_persone_new (OrganigrammaCommons *commons, gboolean selezione)
+*organigramma_persone_new (OrganigrammaCommons *commons, gboolean selezione,
+                           guint id_uffici, GDateTime *when)
 {
        GError *error;
 
@@ -129,6 +133,15 @@ OrganigrammaPersone
 
        priv->commons = commons;
        priv->selezione = selezione;
+       priv->id_uffici = id_uffici;
+       if (when != NULL)
+               {
+                       priv->when = g_date_time_ref (when);
+               }
+       else
+               {
+                       priv->when = NULL;
+               }
 
        error = NULL;
        gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
@@ -203,6 +216,9 @@ organigramma_persone_carica (OrganigrammaPersone *persone)
        GtkTreeIter iter;
 
        gchar *sql;
+       gchar *sql_join;
+       gchar *sql_where;
+
        GdaDataModel *dm;
 
        gint rows;
@@ -212,11 +228,48 @@ organigramma_persone_carica (OrganigrammaPersone *persone)
 
        gtk_list_store_clear (priv->lstore_persone);
 
-       sql = g_strdup_printf ("SELECT c.id, c.cognome || ' ' || c.nome AS cognome_nome"
-                         " FROM persone AS c"
-                         " WHERE c.status <> 'E'"
-                         " ORDER BY c.cognome, c.nome");
+       sql_where = g_strdup ("");
+       sql_join = g_strdup ("");
+       if (priv->id_uffici > 0)
+               {
+                       sql_join = g_strconcat (sql_join,
+                                               " LEFT JOIN persona_uffici AS pu"
+                                               " ON p.id = pu.id_persone",
+                                               NULL);
+                       sql_where = g_strconcat (sql_where,
+                                                g_strdup_printf (" AND pu.id_uffici = %d", priv->id_uffici),
+                                                NULL);
+                       if (priv->when != NULL)
+                               {
+                                       sql_where = g_strconcat (sql_where,
+                                                                g_strdup_printf (" AND pu.da_data <= '%s'"
+                                                                                 " AND (pu.a_data IS NULL OR pu.a_data >= '%s')",
+                                                                                 solipa_gdatetime_format (priv->when, "%F"),
+                                                                                 solipa_gdatetime_format (priv->when, "%F")),
+                                                                NULL);
+                               }
+                       else
+                               {
+                                       sql_where = g_strconcat (sql_where,
+                                                                g_strdup_printf (" AND pu.da_data <= '%s'"
+                                                                                 " AND (pu.a_data IS NULL OR pu.a_data >= '%s')",
+                                                                                 solipa_gdatetime_format (g_date_time_new_now_local (), "%F"),
+                                                                                 solipa_gdatetime_format (g_date_time_new_now_local (), "%F")),
+                                                                NULL);
+                               }
+               }
+
+       sql = g_strdup_printf ("SELECT p.id, p.cognome || ' ' || p.nome AS cognome_nome"
+                         " FROM persone AS p"
+                         "%s"
+                         " WHERE p.status <> 'E'"
+                         "%s"
+                         " ORDER BY p.cognome, p.nome",
+                         sql_join,
+                         sql_where);
        dm = gdaex_query (priv->commons->gdaex, sql);
+       g_free (sql_join);
+       g_free (sql_where);
        g_free (sql);
        if (dm != NULL)
                {
index ff8de5b21859fc82fc26a799af528fb3e4fab13a..d1274e21087880ceb36e6dde2c6f6aced011ffcf 100644 (file)
@@ -55,7 +55,8 @@ struct _OrganigrammaPersoneClass
 
 GType organigramma_persone_get_type (void) G_GNUC_CONST;
 
-OrganigrammaPersone *organigramma_persone_new (OrganigrammaCommons *commons, gboolean selezione);
+OrganigrammaPersone *organigramma_persone_new (OrganigrammaCommons *commons, gboolean selezione,
+                                               guint id_uffici, GDateTime *when);
 
 GtkWidget *organigramma_persone_get_widget (OrganigrammaPersone *persone);