fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [10360] api: attribute groups within attribute groups


From: Sigurd Nes
Subject: [Fmsystem-commits] [10360] api: attribute groups within attribute groups
Date: Sun, 28 Oct 2012 16:38:26 +0000

Revision: 10360
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10360
Author:   sigurdne
Date:     2012-10-28 16:38:26 +0000 (Sun, 28 Oct 2012)
Log Message:
-----------
api: attribute groups within attribute groups

Modified Paths:
--------------
    trunk/phpgwapi/inc/class.custom_fields.inc.php

Modified: trunk/phpgwapi/inc/class.custom_fields.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.custom_fields.inc.php      2012-10-28 16:36:50 UTC 
(rev 10359)
+++ trunk/phpgwapi/inc/class.custom_fields.inc.php      2012-10-28 16:38:26 UTC 
(rev 10360)
@@ -77,6 +77,8 @@
                protected $_total_records = 0;
 
                protected $global_lock = false;
+               
+               protected $attribute_group_tree = array();
 
                /**
                 * Constructor
@@ -179,11 +181,17 @@
                                'parent_id'             => $group['parent_id']
                        );
 
+                       $filter_parent = '';
+                       if($group['parent_id'])
+                       {
+                               $filter_parent = ' AND parent_id = ' . (int) 
$group['parent_id'];
+                       }
 
                        unset($group);
 
                        $this->_db->transaction_begin();
 
+/*
                        $sql = "SELECT id FROM phpgw_cust_attribute_group"
                                . " WHERE location_id = 
{$values['location_id']}"
                                        . " AND name = '{$values['name']}'";
@@ -192,14 +200,22 @@
                        {
                                return -1;
                        }
-
-                       $sql = 'SELECT MAX(group_sort) AS max_sort, MAX(id) AS 
current_id'
+*/
+                       
+                       $sql = 'SELECT MAX(id) AS current_id'
                                . ' FROM phpgw_cust_attribute_group '
                                . " WHERE location_id 
='{$values['location_id']}'";
                        $this->_db->query($sql, __LINE__, __FILE__);
                        $this->_db->next_record();
+                       $values['id']   = $this->_db->f('current_id') + 1;      
        
+
+                       $sql = 'SELECT MAX(group_sort) AS max_sort'
+                               . ' FROM phpgw_cust_attribute_group '
+                               . " WHERE location_id 
='{$values['location_id']}'{$filter_parent}";
+
+                       $this->_db->query($sql, __LINE__, __FILE__);
+                       $this->_db->next_record();
                        $values['group_sort']   = $this->_db->f('max_sort') + 1;
-                       $values['id']   = $this->_db->f('current_id') + 1;      
        
                        
                        $cols = implode(', ', array_keys($values));
                        $vals = $this->_db->validate_insert($values);
@@ -1103,6 +1119,8 @@
 
                        return $attribs;
                }
+
+
                /**
                 * Get a list of groups availlable for attributes within a 
location
                 *
@@ -1116,6 +1134,7 @@
                 *
                 * @return ???? something
                 */
+
                public function find_group($appname, $location, $start = 0, 
$query = '', $sort = 'ASC',
                                $order = 'group_sort', $allrows = false)
                {
@@ -1142,46 +1161,105 @@
                                $querymethod = "AND 
(phpgw_cust_attribute_group.name {$this->_like} '%{$query}%'";
                        }
 
-                       $sql = "FROM phpgw_cust_attribute_group "
-                               . " WHERE location_id = {$location_id} 
{$querymethod}";
+                       $sql = "SELECT * FROM phpgw_cust_attribute_group "
+                               . " WHERE location_id = {$location_id} AND 
(parent_id = 0 OR parent_id IS NULL) {$querymethod} {$ordermethod}";
 
-                       $this->_total_records = 0;
-                       $this->_db->query("SELECT COUNT(*) AS cnt_rec 
{$sql}",__LINE__,__FILE__);
-                       if ( !$this->_db->next_record() )
+
+                       $this->_db->query($sql,__LINE__,__FILE__);
+
+                       $this->attribute_group_tree = array();
+                       while ($this->_db->next_record())
                        {
-                               return array();
+                               $id                     = $this->_db->f('id');
+                               $group_sort = (int) $this->_db->f('group_sort');
+                               $groups[$id] = array
+                               (
+                                       'id'                            => $id,
+                                       'name'                          => 
$this->_db->f('name',true),
+                                       'parent_id'                     => 0,
+                                       'group_sort'            => $group_sort,
+                                       'group_sort_text'       => $group_sort,
+                                       'descr'                         => 
$this->_db->f('descr', true),
+                                       'remark'                        => 
$this->_db->f('remark', true),
+                               );
                        }
 
-                       $this->_total_records = $this->_db->f('cnt_rec');
+                       foreach($groups as $group)
+                       {
+                               $this->attribute_group_tree[] = array
+                               (
+                                       'id'                            => 
$group['id'],
+                                       'name'                          => 
$group['name'],
+                                       'parent_id'                     => 0,
+                                       'group_sort'            => 
$group['group_sort'],
+                                       'group_sort_text'       => 
$group['group_sort'],
+                                       'descr'                         => 
$group['descr'],
+                                       'remark'                        => 
$group['remark'],
+                               );
+                               
$this->get_attribute_group_children($location_id, 
$group['id'],$group['group_sort'], 1, false);
+                       }
 
-                       $sql = "SELECT * {$sql} {$ordermethod}";
+                       $this->_total_records = 
count($this->attribute_group_tree);
+                       $result = $this->attribute_group_tree;
 
-                       if ( $allrows )
+                       if($this->total_records == 0)
                        {
-                               $this->_db->query($sql, __LINE__, __FILE__);
+                               return $result;
                        }
+
+                       if(!$allrows)
+                       {
+                               $num_rows = 
isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) ? 
(int) $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']:15;
+
+                               $page = ceil( ( $start / $this->total_records ) 
* ($this->total_records/ $num_rows) );
+
+                               $out = array_chunk($result, $num_rows);
+
+                               return $out[$page];
+                       }
                        else
                        {
-                               $this->_db->limit_query($sql, $start, __LINE__, 
__FILE__);
+                               return $result;
                        }
 
-                       $attrib_groups = array();
-                       while ( $this->_db->next_record() )
+                       return $this->attribute_group_tree;
+               }
+
+
+               function get_attribute_group_children($location_id, $parent, 
$parent_sort, $level, $reset = false)
+               {
+                       if($reset)
                        {
-                               $attrib_groups[] = array
+                               $this->attribute_group_tree = array();
+                       }
+
+                       $filtermethod = 'WHERE location_id =' . 
(int)$location_id;                      
+
+                       $db = clone($this->_db);
+                       $sql = "SELECT * FROM phpgw_cust_attribute_group 
$filtermethod AND parent_id = {$parent} ORDER BY group_sort ASC";
+
+                       $db->query($sql,__LINE__,__FILE__);
+
+                       while ($db->next_record())
+                       {
+                               $id                                     = 
$db->f('id');
+                               $group_sort                     = 
$db->f('group_sort');
+                               $group_sort_text        = $parent_sort ? 
"{$parent_sort}::{$group_sort}" : $group_sort;
+                               $this->attribute_group_tree[] = array
                                (
-                                       'id'                            => 
$this->_db->f('id'),
-                                       'group_sort'            => (int) 
$this->_db->f('group_sort'),
-                                       'name'                          => 
$this->_db->f('name', true),
-                                       'descr'                         => 
$this->_db->f('descr', true),
-                                       'remark'                        => 
$this->_db->f('remark', true),
-                                       'parent_id'                     => 
$this->_db->f('parent_id'),
+                                       'id'                            => $id,
+                                       'name'                          => 
str_repeat('..',$level).$db->f('name'),
+                                       'parent_id'                     => 
$db->f('parent_id'),
+                                       'group_sort'            => $group_sort,
+                                       'group_sort_text'       => 
$group_sort_text,
+                                       'descr'                         => 
$db->f('descr'),
+                                       'remark'                        => 
$db->f('remark'),
                                );
+                               
$this->get_attribute_group_children($location_id, $id, $group_sort_text, 
$level+1);
                        }
+                       return $this->attribute_group_tree;
+               } 
 
-                       return $attrib_groups;
-               }
-
                /**
                * Read a single attribute group record
                *
@@ -1452,14 +1530,24 @@
 
                        $this->_db->transaction_begin();
 
-                       $sql = "SELECT group_sort FROM 
phpgw_cust_attribute_group "
+                       $sql = "SELECT group_sort,parent_id FROM 
phpgw_cust_attribute_group "
                                . " WHERE location_id = {$location_id} AND id = 
{$id}";
                        $this->_db->query($sql, __LINE__, __FILE__);
                        $this->_db->next_record();
                        $attrib_sort    = $this->_db->f('group_sort');
+                       $parent_id              = 
(int)$this->_db->f('parent_id');
+                       if($parent_id)
+                       {
+                               $filter_parent = "AND parent_id = {$parent_id}";
+                       }
+                       else
+                       {
+                               $filter_parent = "AND (parent_id = 0 OR 
parent_id IS NULL)";
+                       }
 
                        $sql = "SELECT MAX(group_sort) AS max_sort FROM 
phpgw_cust_attribute_group "
-                               . " WHERE location_id = {$location_id}";
+                               . " WHERE location_id = {$location_id} 
{$filter_parent}";
+
                        $this->_db->query($sql,__LINE__,__FILE__);
                        $this->_db->next_record();
                        $max_sort       = $this->_db->f('max_sort');
@@ -1492,7 +1580,7 @@
                        }
 
                        $sql = "UPDATE phpgw_cust_attribute_group SET 
group_sort = {$attrib_sort}"
-                               . " WHERE location_id = {$location_id} AND 
group_sort = {$new_sort}";
+                               . " WHERE location_id = {$location_id} AND 
group_sort = {$new_sort} {$filter_parent}";
                        $this->_db->query($sql, __LINE__, __FILE__);
 
                        $sql = "UPDATE phpgw_cust_attribute_group SET 
group_sort = {$new_sort}"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]