[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [7126] property: enable hierarchy at generic
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [7126] property: enable hierarchy at generic |
Date: |
Wed, 16 Mar 2011 15:17:16 +0000 |
Revision: 7126
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7126
Author: sigurdne
Date: 2011-03-16 15:17:15 +0000 (Wed, 16 Mar 2011)
Log Message:
-----------
property: enable hierarchy at generic
Modified Paths:
--------------
trunk/property/inc/class.bogeneric.inc.php
trunk/property/inc/class.soadmin_entity.inc.php
trunk/property/inc/class.sogeneric.inc.php
trunk/property/inc/class.uigeneric.inc.php
trunk/property/setup/setup.inc.php
trunk/property/setup/tables_current.inc.php
trunk/property/setup/tables_update.inc.php
Modified: trunk/property/inc/class.bogeneric.inc.php
===================================================================
--- trunk/property/inc/class.bogeneric.inc.php 2011-03-15 10:30:56 UTC (rev
7125)
+++ trunk/property/inc/class.bogeneric.inc.php 2011-03-16 15:17:15 UTC (rev
7126)
@@ -198,7 +198,16 @@
public function get_list($data)
{
- $values = $this->so->get_list($data);
+
+ if(isset($data['role']) && $data['role'] == 'parent')
+ {
+ $values = $this->so->get_tree2($data);
+ }
+ else
+ {
+ $values = $this->so->get_list($data);
+ }
+
if(isset($data['selected']) &&
is_array($data['selected']))
{
foreach ($values as &$entry)
@@ -220,4 +229,9 @@
{
$this->so->delete($id);
}
+
+ public function get_children2($id, $level, $reset = false)
+ {
+ return $this->so->get_children2($id, $level, $reset);
+ }
}
Modified: trunk/property/inc/class.soadmin_entity.inc.php
===================================================================
--- trunk/property/inc/class.soadmin_entity.inc.php 2011-03-15 10:30:56 UTC
(rev 7125)
+++ trunk/property/inc/class.soadmin_entity.inc.php 2011-03-16 15:17:15 UTC
(rev 7126)
@@ -352,7 +352,7 @@
}
/**
- * used for retrive the pathe for a particular node from a
hierarchy
+ * used for retrive the path for a particular node from a
hierarchy
*
* @param integer $entity_id Entity id
* @param integer $node is the id of the node we want the path
of
Modified: trunk/property/inc/class.sogeneric.inc.php
===================================================================
--- trunk/property/inc/class.sogeneric.inc.php 2011-03-15 10:30:56 UTC (rev
7125)
+++ trunk/property/inc/class.sogeneric.inc.php 2011-03-16 15:17:15 UTC (rev
7126)
@@ -37,6 +37,8 @@
var $type;
var $type_id;
var $location_info = array();
+ var $tree = array();
+ protected $table;
function __construct()
{
@@ -1573,6 +1575,21 @@
(
array
(
+ 'name'
=> 'parent_id',
+ 'descr'
=> lang('parent'),
+ 'type'
=> 'select',
+ 'nullable'
=> true,
+ 'filter'
=> false,
+ 'role'
=> 'parent',
+ 'values_def'
=> array
+ (
+
'valueset' => false,
+
'method' => 'property.bogeneric.get_list',
+
'method_input' => array('type' => 'regulations', 'role' => 'parent',
'selected' => '##parent_id##')
+ )
+ ),
+ array
+ (
'name' =>
'name',
'descr' =>
lang('name'),
'type' =>
'varchar'
@@ -2268,6 +2285,7 @@
{
$value_set = array_merge($value_set,
$data_attribute['value_set']);
}
+
foreach($this->location_info['fields'] as $field)
{
if (isset($field['filter']) && $field['filter'])
@@ -2278,6 +2296,13 @@
}
}
$value_set[$field['name']] =
$this->_db->db_addslashes($data[$field['name']]);
+
+ if(isset($field['role']) && $field['role'] ==
'parent')
+ {
+ //FIXME
+
+
+ }
}
if(isset($this->location_info['default']) &&
is_array($this->location_info['default']))
@@ -2321,5 +2346,172 @@
}
$this->_db->query("DELETE FROM $table WHERE
{$this->location_info['id']['name']}='{$id}'",__LINE__,__FILE__);
}
+
+
+ public function get_tree2($data)
+ {
+ $values = array();
+
+ $this->get_location_info($data['type'],
$data['type_id']);
+
+ if (!isset($this->location_info['table']) || !$table =
$this->location_info['table'])
+ {
+ return $values;
+ }
+ $this->table = $table;
+
+ $filtermthod = 'WHERE (parent_id = 0 OR parent_id IS
NULL)';
+
+ if (isset($data['filter']) && is_array($data['filter']))
+ {
+ $_filter = array();
+ foreach ($data['filter'] as $_field => $_value)
+ {
+ $_filter[] = "{$_field} = '{$_value}'";
+ }
+ if($_filter)
+ {
+ $filtermthod .= implode(' AND ',
$_filter);
+ }
+ }
+
+ $order = isset($data['order']) &&
$data['order'] ? $data['order'] :'';
+
+ if ($order)
+ {
+ $ordermethod = " ORDER BY {$table}.{$order}
{$sort}";
+ }
+ else
+ {
+ $ordermethod = " ORDER BY
{$table}.{$this->location_info['id']['name']} ASC";
+ }
+
+ foreach ($this->location_info['fields'] as $field)
+ {
+ $fields[] = $field['name'];
+ }
+
+ // Add extra info to name
+ if(isset($data['id_in_name']) && $data['id_in_name'])
+ {
+ $id_in_name = 'id';
+ if (in_array($data['id_in_name'], $fields))
+ {
+ $id_in_name = $data['id_in_name'];
+ }
+ }
+
+ $fields = implode(',', $fields);
+
+ $this->_db->query("SELECT id, {$fields} FROM {$table}
{$filtermthod} {$ordermethod}",__LINE__,__FILE__);
+
+ $return_fields = isset($data['fields']) &&
$data['fields'] && is_array($data['fields']) ? $data['fields'] : array();
+//-----------
+
+
+ $values = array();
+ $i = 0;
+ while ($this->_db->next_record())
+ {
+ $_extra = $this->_db->f($id_in_name);
+ $id = $this->_db->f('id');
+ if(!$name = $this->_db->f('name', true))
+ {
+ $name = $this->_db->f('descr', true);
+ }
+
+ if($_extra)
+ {
+ $name = "{$_extra} - {$name}";
+ }
+
+ $values[$i] = array
+ (
+ 'id' => $id,
+ 'name' => $name,
+ 'parent_id' => 0
+ );
+
+ foreach ($return_fields as $return_field)
+ {
+ $values[$i][$return_field] =
$this->_db->f($return_field, true);
+ }
+
+ $i++;
+ }
+
+
+ $this->tree = array();
+
+ foreach($values as $value)
+ {
+ $this->tree[] = $value;
+ $this->get_children2($value['id'], 1);
+ }
+ return $this->tree;
+ }
+
+ public function get_children2($parent, $level, $reset = false)
+ {
+ if($reset)
+ {
+ $this->tree = array();
+ }
+ $db = clone($this->_db);
+ if(!$table = $this->table)
+ {
+ return $this->tree;
+ }
+ $sql = "SELECT * FROM {$table} WHERE parent_id =
{$parent} ORDER BY name ASC";
+ $db->query($sql,__LINE__,__FILE__);
+
+ while ($db->next_record())
+ {
+ $id = $db->f('id');
+ $this->tree[] = array
+ (
+ 'id' => $id,
+ 'name' =>
str_repeat('..',$level) . $db->f('name',true),
+ 'parent_id' => $db->f('parent_id')
+ );
+ $this->get_children2($id, $level+1);
+ }
+ return $this->tree;
+ }
+
+ /**
+ * used for retrive the path for a particular node from a
hierarchy
+ *
+ * @param integer $node is the id of the node we want the path
of
+ * @return array $path Path
+ */
+
+ public function get_path($data)
+ {
+ $this->get_location_info($data['type'],
$data['type_id']);
+
+ if (!isset($this->location_info['table']) || !$table =
$this->location_info['table'])
+ {
+ return array();
+ }
+ $this->table = $table;
+
+ $sql = "SELECT name, parent_id FROM {$table} WHERE id =
'{$data['id']}'";
+
+ $this->_db->query($sql,__LINE__,__FILE__);
+ $this->_db->next_record();
+
+ $parent_id = $this->_db->f('parent_id');
+
+ $name = $this->_db->f('name', true);
+
+ $path = array($name);
+
+ if ($parent_id)
+ {
+ $path =
array_merge($this->get_path(array('type' => $data['type'], 'id' =>
$parent_id)), $path);
+ }
+ return $path;
+ }
}
Modified: trunk/property/inc/class.uigeneric.inc.php
===================================================================
--- trunk/property/inc/class.uigeneric.inc.php 2011-03-15 10:30:56 UTC (rev
7125)
+++ trunk/property/inc/class.uigeneric.inc.php 2011-03-16 15:17:15 UTC (rev
7126)
@@ -792,6 +792,26 @@
$field['valueset'] =
execMethod($field['values_def']['method'],$method_input);
}
+
+ if(isset($values['id']) &&
$values['id'] && isset($field['role']) && $field['role'] == 'parent')
+ {
+ $exclude = array($values['id']);
+ $children =
$this->bo->get_children2($values['id'], 0,true);
+
+ foreach($children as $child)
+ {
+ $exclude[] =
$child['id'];
+ }
+
+ $k = count($field['valueset']);
+ for ($i=0; $i<$k; $i++)
+ {
+ if
(in_array($field['valueset'][$i]['id'],$exclude))
+ {
+
unset($field['valueset'][$i]);
+ }
+ }
+ }
}
}
Modified: trunk/property/setup/setup.inc.php
===================================================================
--- trunk/property/setup/setup.inc.php 2011-03-15 10:30:56 UTC (rev 7125)
+++ trunk/property/setup/setup.inc.php 2011-03-16 15:17:15 UTC (rev 7126)
@@ -12,7 +12,7 @@
*/
$setup_info['property']['name'] = 'property';
- $setup_info['property']['version'] = '0.9.17.613';
+ $setup_info['property']['version'] = '0.9.17.614';
$setup_info['property']['app_order'] = 8;
$setup_info['property']['enable'] = 1;
$setup_info['property']['app_group'] = 'office';
Modified: trunk/property/setup/tables_current.inc.php
===================================================================
--- trunk/property/setup/tables_current.inc.php 2011-03-15 10:30:56 UTC (rev
7125)
+++ trunk/property/setup/tables_current.inc.php 2011-03-16 15:17:15 UTC (rev
7126)
@@ -2221,6 +2221,7 @@
'fm_regulations' => array(
'fd' => array(
'id' => array('type' => 'int','precision' =>
4,'nullable' => False),
+ 'parent_id' => array('type' =>
'int','precision' => 4,'nullable' => True),
'name' => array('type' =>
'varchar','precision' => 255,'nullable' => False),
'descr' => array('type' => 'text','nullable' =>
True),
'external_ref' => array('type' =>
'varchar','precision' => 255,'nullable' => True),
Modified: trunk/property/setup/tables_update.inc.php
===================================================================
--- trunk/property/setup/tables_update.inc.php 2011-03-15 10:30:56 UTC (rev
7125)
+++ trunk/property/setup/tables_update.inc.php 2011-03-16 15:17:15 UTC (rev
7126)
@@ -5145,7 +5145,27 @@
}
}
+ /**
+ * Update property version from 0.9.17.613 to 0.9.17.614
+ * Add parent to regulations
+ *
+ */
+ $test[] = '0.9.17.613';
+ function property_upgrade0_9_17_613()
+ {
+ $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
+
+
$GLOBALS['phpgw_setup']->oProc->AddColumn('fm_regulations','parent_id',
array('type' => 'int','precision' => 4,'nullable' => True));
+
+ if($GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit())
+ {
+ $GLOBALS['setup_info']['property']['currentver'] =
'0.9.17.614';
+ return $GLOBALS['setup_info']['property']['currentver'];
+ }
+ }
+
+
/**
* Update property version from 0.9.17.607 to 0.9.17.608
* Add more room for address at tickets
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [7126] property: enable hierarchy at generic,
Sigurd Nes <=