[ghelda-devel] [43] plugins/Groups ongoing work : Now works mostly

[ Thread Index | Date Index | More lists.tuxfamily.org/ghelda-devel Archives ]


Revision: 43
Author:   odyx
Date:     2009-05-20 13:48:18 +0200 (Wed, 20 May 2009)

Log Message:
-----------
plugins/Groups ongoing work : Now works mostly

Modified Paths:
--------------
    trunk/plugins/Groups/config.php
    trunk/plugins/Groups/config_core.php
    trunk/plugins/Groups.php


Modified: trunk/plugins/Groups/config.php
===================================================================
--- trunk/plugins/Groups/config.php	2009-05-20 11:48:16 UTC (rev 42)
+++ trunk/plugins/Groups/config.php	2009-05-20 11:48:18 UTC (rev 43)
@@ -30,8 +30,11 @@
 $conf['fields_link']['role']['values'][2]['values'][19] = T_('Troup Chief');
 $conf['fields_link']['role']['values'][2]['values'][18] = T_('Troup Chief Adjunct');
 
-$conf['orderby'][] = 'type';
-$conf['orderby'][] = 'name';
+$conf['groups_orderby'][] = 'type';
+$conf['groups_orderby'][] = 'name';
 
+$conf['link_orderby']['list'][] = 'start_date';
+$conf['link_orderby']['order'] = 'DESC';
 
+
 ?>

Modified: trunk/plugins/Groups/config_core.php
===================================================================
--- trunk/plugins/Groups/config_core.php	2009-05-20 11:48:16 UTC (rev 42)
+++ trunk/plugins/Groups/config_core.php	2009-05-20 11:48:18 UTC (rev 43)
@@ -41,6 +41,11 @@
 $conf['fields_link']['people_group_id']['name'] = T_('Identifier');
 $conf['fields_link']['people_group_id']['restricted'] = 'key';
 
+$conf['fields_link'][G_GROUPS_ID]['type'] = 'SELECT';
+$conf['fields_link'][G_GROUPS_ID]['name'] = T_('Group');
+$conf['fields_link'][G_GROUPS_ID]['optgroups'] = true;
+$conf['fields_link'][G_GROUPS_ID]['multiple'] = false;
+
 $conf['fields_link']['start_date']['type'] = 'DATE';
 $conf['fields_link']['start_date']['name'] = T_('Start date');
 

Modified: trunk/plugins/Groups.php
===================================================================
--- trunk/plugins/Groups.php	2009-05-20 11:48:16 UTC (rev 42)
+++ trunk/plugins/Groups.php	2009-05-20 11:48:18 UTC (rev 43)
@@ -279,13 +279,52 @@
         // Modification asked
         if($_POST[$this->configH['URL']['action']] == 'change') {
             // Get the fields from the keyed array
-            $fields = array_keys($this->configH[$this->name]['fields_link']);
-            gold('fields = ', $fields);
+            $fields_link = $this->configH[$this->name]['fields_link'];
             // Go along the various Group'IDs
             foreach( $_POST[$this->name.'_'.G_GROUPS_ID] as $pg_id => $group_id ) {
-                trigger_error($pg_id.' => '.$group_id,G_E_DISPLAY);
-                // If the group_id has not been chosen => we have nothing to write
-                if( $group_id == G_GROUPS_ID_NEW ) continue;
+                // $pg_id is the "people-to-group" identifier
+                // $group_id is the "group" identifier
+
+                $formattedFields = array();
+                foreach($fields_link as $fieldName => $fieldSpec) {
+                    // Jump the key thingie
+                    if( array_key_exists('restricted',$fieldSpec) && $fieldSpec['restricted'] == 'key') continue;
+
+                    $formattedField = 
+                        g_getFormattedField($_POST,$fieldSpec['type'],$this->name.'_'.$fieldName,$fieldSpec,$pg_id);
+                    $formattedFields[] = '`'.$fieldName.'`'.' = '."'".$formattedField."'";
+                }
+                // If we actually have something to do
+                if( $group_id != G_GROUPS_ID_NEW || $pg_id != G_GROUPS_ID_NEW ) {
+                    // If we are deleting an entry
+                    if( $group_id == G_GROUPS_ID_NEW ) {
+                    $query = sprintf("DELETE FROM `%s` WHERE `%s` = '%s' LIMIT 1",
+                        $this->linkPeopleTableName,
+                        'people_group_id',
+                        $pg_id
+                        );
+                    }
+                    // If we are creating a new one
+                    elseif( $pg_id == G_GROUPS_ID_NEW ) {
+                        $formattedFields[] = '`'.G_DB_PEOPLE_ID.'`'.' = '."'".$id_people."'";
+                        $query = sprintf("INSERT INTO `%s` SET %s ",
+                            $this->linkPeopleTableName,
+                            implode(', ',$formattedFields)
+                            );
+                    }
+                    // If we are updating an existing one
+                    else {
+                        $query = sprintf("UPDATE `%s` SET %s WHERE `%s` = '%s' LIMIT 1",
+                            $this->linkPeopleTableName,
+                            implode(', ',$formattedFields),
+                            'people_group_id',
+                            $pg_id
+                            );
+                    }
+                    $queryR =& $this->db->query($query);
+                    if(PEAR::isError($queryR))
+                        return false;
+                }
             }
         }
 
@@ -295,7 +334,7 @@
         array_walk($tableFieldsNames,'concat_to_each',array('`'.$this->tableName.'`.`','`'));
 
         // Get the Ordering
-        $tableOrderBy = $this->configH[$this->name]['orderby'];
+        $tableOrderBy = $this->configH[$this->name]['groups_orderby'];
         array_walk($tableOrderBy,'concat_to_each',array('`'.$this->tableName.'`.`','`'));
 
         // Get listof groups
@@ -308,7 +347,7 @@
             return false;
 
         // Create empty fake one
-        $groups[G_GROUPS_ID_NEW]['name'] = '';
+        $groups[G_GROUPS_ID_NEW]['name'] = T_('Par défaut');
         $groups[G_GROUPS_ID_NEW]['values'] = array(G_GROUPS_ID_NEW => '');
 
         while (($groups_row = $queryR->fetchRow())) {
@@ -325,50 +364,55 @@
         $variablesChain = array_merge($tableFieldsNames,$linkTableFieldsNames);
         $variablesChain = implode(',',$variablesChain);
 
+        // Order by ?
+        $orderBy = $this->configH[$this->name]['link_orderby']['list'];
+        array_walk($orderBy,'concat_to_each',array('`'.$this->linkPeopleTableName.'`.`','`'));
+
+
         // Display list of connections + one empty
         // TODO: No LIMIT !
-        $query = sprintf("SELECT %s FROM `%s` WHERE `%s` = `%s` AND `%s` = '%s'",
+        $query = sprintf("SELECT %s FROM `%s` WHERE `%s` = `%s` AND `%s` = '%s' ORDER BY %s %s",
                 $variablesChain,
                 implode('`,`',array($this->linkPeopleTableName,$this->tableName)),
                 implode('`.`',array($this->linkPeopleTableName,G_GROUPS_ID)),
                 implode('`.`',array($this->tableName,G_GROUPS_ID)),
                 G_DB_PEOPLE_ID,
-                $id_people);
+                $id_people,
+                implode(',',$orderBy),
+                $this->configH[$this->name]['link_orderby']['order']
+                );
         $queryR =& $this->db->query($query);
         if(PEAR::isError($queryR))
             return false;
 
         while (($pg_row = $queryR->fetchRow())) {
             $key = $pg_row[G_PEOPLE_GROUPS_ID];
-            $to_return['content'][G_GROUPS_ID.'['.$key.']'] = $pg_row[G_GROUPS_ID];
-            $to_return['spec'][G_GROUPS_ID.'['.$key.']'] = array(
-                'type' => 'SELECT',
-                'name' => T_('Group'),
-                'optgroups' => true,
-                'values' => $groups,
-                'multiple' => false
-            );
             foreach($linkTableFields as $fieldName => $fieldSpecs) {
-                if( array_key_exists('restricted',$fieldSpecs) ) continue;
+                // Don't display our key field
+                if( array_key_exists('restricted',$fieldSpecs) && $fieldsSpecs['restricted'] == 'key' ) continue;
 
                 $to_return['spec'][$fieldName.'['.$key.']'] = $fieldSpecs;
                 $to_return['content'][$fieldName.'['.$key.']'] = $pg_row[$fieldName];
+
+                // If the current field is our key one, push the groups spec array inside
+                if( $fieldName == G_GROUPS_ID ) {
+                    $to_return['spec'][$fieldName.'['.$key.']']['values'] = $groups;
+                }
             }
         }
-        // Add a fake entry
+        // Add a fake entry (aka run the while loop once more)
         $key = G_GROUPS_ID_NEW;
-        $to_return['spec'][G_GROUPS_ID.'['.$key.']'] = array(
-                'type' => 'SELECT',
-                'name' => T_('Group'),
-                'optgroups' => true,
-                'values' => $groups,
-                'multiple' => false
-        );
-        // Inputs display possible with name=id='field_name[identifiant]'
         foreach($linkTableFields as $fieldName => $fieldSpecs) {
-            if( array_key_exists('restricted',$fieldSpecs) ) continue;
+            // Don't display our key field
+            if( array_key_exists('restricted',$fieldSpecs) && $fieldsSpecs['restricted'] == 'key' ) continue;
+
             $to_return['spec'][$fieldName.'['.$key.']'] = $fieldSpecs;
             $to_return['content'][$fieldName.'['.$key.']'] = $pg_row[$fieldName];
+
+            // If the current field is our key one, push the groups spec array inside
+            if( $fieldName == G_GROUPS_ID ) {
+                $to_return['spec'][$fieldName.'['.$key.']']['values'] = $groups;
+            }
         }
 
         $this->stopTrad();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/