fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [10329] logistic: list hierarchy at activities


From: Sigurd Nes
Subject: [Fmsystem-commits] [10329] logistic: list hierarchy at activities
Date: Wed, 24 Oct 2012 11:38:00 +0000

Revision: 10329
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10329
Author:   sigurdne
Date:     2012-10-24 11:37:59 +0000 (Wed, 24 Oct 2012)
Log Message:
-----------
logistic: list hierarchy at activities

Modified Paths:
--------------
    trunk/logistic/inc/class.soactivity.inc.php
    trunk/logistic/inc/class.uiactivity.inc.php

Modified: trunk/logistic/inc/class.soactivity.inc.php
===================================================================
--- trunk/logistic/inc/class.soactivity.inc.php 2012-10-24 08:20:08 UTC (rev 
10328)
+++ trunk/logistic/inc/class.soactivity.inc.php 2012-10-24 11:37:59 UTC (rev 
10329)
@@ -33,6 +33,7 @@
        class logistic_soactivity extends logistic_socommon
        {
                protected static $so;
+               protected $activity_tree = array();
 
                /**
                 * Get a static reference to the storage object associated with 
this model object
@@ -201,6 +202,147 @@
                        return "SELECT {$cols} FROM {$tables} WHERE 
{$condition} {$order}";
                }
 
+
+               /**
+                * Method for retreiving objects.
+                * 
+                * @param $start_index int with index of first object.
+                * @param $num_of_objects int with max number of objects to 
return.
+                * @param $sort_field string representing the object field to 
sort on.
+                * @param $ascending boolean true for ascending sort on sort 
field, false
+                * for descending.
+                * @param $search_for string with free text search query.
+                * @param $search_type string with the query type.
+                * @param $filters array with key => value of filters.
+                * @return array of objects. May return an empty
+                * array, never null. The array keys are the respective index 
numbers.
+                */
+               public function get(int $start_index, int $num_of_objects, 
string $sort_field, boolean $ascending, string $search_for, string 
$search_type, array $filters)
+               {
+                       $results = array();                     // Array to 
store result objects
+                       $map = array();                         // Array to 
hold number of records per target object
+                       $check_map = array();           // Array to hold the 
actual number of record read per target object
+                       $object_ids = array();          // All of the object 
ids encountered
+                       $added_object_ids = array();// All of the added objects 
ids
+
+                       // Retrieve information about the table name and the 
name and alias of id column
+                       // $break_on_limit -    flag indicating whether to 
break the loop when the number of records 
+                       //                                              for all 
the result objects are traversed
+                       $id_field_name_info = $this->get_id_field_name(true);
+                       if(is_array($id_field_name_info))
+                       {
+                               $break_on_limit = true;
+                               $id_field_name = 
$id_field_name_info['translated'];
+                       }
+                       else
+                       {
+                               $break_on_limit = false;
+                               $id_field_name = $id_field_name_info;
+                       }
+
+                       // Special case: Sort on id field. Always changed to 
the id field name.
+                       // $break_when_num_of_objects_reached - flag indicating 
to break the loop when the number of 
+                       //              results are reached and we are sure 
that the records are ordered by the id
+                       if($sort_field == null || $sort_field == 'id' || 
$sort_field == '')
+                       {
+                               $sort_field = $id_field_name;
+                               $break_when_num_of_objects_reached = true;
+                       }
+                       else
+                       {
+                               $break_when_num_of_objects_reached = false;
+                       }
+
+                       // Only allow positive start index
+                       if($start_index < 0)
+                       {
+                               $start_index = 0;
+                       }
+
+                       $sql = $this->get_query($sort_field, $ascending, 
$search_for, $search_type, $filters, false);
+
+                       $ret = $this->read_tree($sql, $filters);
+
+                       return $ret;
+               }
+
+               public function read_tree($sql, $filters)
+               {
+                       if($filters['activity'])
+                       {
+                               $filter_clause = "activity.id = 
{$this->marshal($filters['activity'], 'int')}";
+                       }
+                       else
+                       {
+                               $filter_clause = "(parent_activity_id = 0 OR 
parent_activity_id IS NULL)";
+                       }
+
+                       $sql_parts = explode('1=1',$sql); // Split the query to 
insert extra condition on test for break
+                       $sql = "{$sql_parts[0]} {$filter_clause} 
{$sql_parts[1]}";
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+
+                       $this->activity_tree = array();
+                       while ($this->db->next_record())
+                       {
+                               $id     = $this->db->f('id');
+                               $activities[$id] = array
+                                       (
+                                               'id'                    => $id,
+                                               'name'                  => 
$this->db->f('name',true),
+                                               'parent_id'             => 0
+                                       );
+                       }
+
+                       foreach($activities as $activity)
+                       {
+                               $this->activity_tree[] = array
+                                       (
+                                               'id'    => $activity['id'],
+                                               'name'  => $activity['name']
+                                       );
+                               $this->get_children($activity['id'], 1);
+                       }
+
+                       $result = array();
+                       foreach($this->activity_tree as $_activity)
+                       {
+                               $this->db->query("SELECT * FROM lg_activity 
WHERE id ={$_activity['id']}",__LINE__,__FILE__);
+                               $this->db->next_record();
+                               $activity_obj = 
$this->populate($_activity['id']);
+                               $activity_obj->set_name($_activity['name']);
+                               $result[] = $activity_obj;
+                       }
+
+                       return $result;
+               }
+
+               function get_children($parent, $level, $reset = false)
+               {
+                       if($reset)
+                       {
+                               $this->activity_tree = array();
+                       }
+                       $db = clone($this->db);
+                       $table = "lg_activity";
+                       $sql = "SELECT id, name FROM {$table} WHERE 
parent_activity_id = {$parent} ORDER BY name ASC";
+                       $db->query($sql,__LINE__,__FILE__);
+
+                       while ($db->next_record())
+                       {
+                               $id     = $db->f('id');
+                               $this->activity_tree[] = array
+                                       (
+                                               'id'            => $id,
+                                               'name'          => 
str_repeat('..',$level).$db->f('name',true),
+                                               'parent_id'     => $parent
+                                       );
+                               $this->get_children($id, $level+1);
+                       }
+                       return $this->activity_tree;
+               } 
+
+
                protected function populate(int $activity_id, &$activity)
                {
                        if($activity == null)
@@ -252,4 +394,4 @@
                                }
                        }
                }
-       }
\ No newline at end of file
+       }

Modified: trunk/logistic/inc/class.uiactivity.inc.php
===================================================================
--- trunk/logistic/inc/class.uiactivity.inc.php 2012-10-24 08:20:08 UTC (rev 
10328)
+++ trunk/logistic/inc/class.uiactivity.inc.php 2012-10-24 11:37:59 UTC (rev 
10329)
@@ -98,7 +98,7 @@
                                        ),
                                ),
                                'datatable' => array(
-                                       'source' => 
self::link(array('menuaction' => 'logistic.uiactivity.index', 'phpgw_return_as' 
=> 'json')),
+                                       'source' => 
self::link(array('menuaction' => 'logistic.uiactivity.index', 'phpgw_return_as' 
=> 'json', 'filter' => phpgw::get_var('filter', 'int'))),
                                        'field' => array(
                                                array(
                                                        'key' => 'name',
@@ -276,7 +276,7 @@
                        {
                                default: // ... all activities, filters (active 
and vacant)
                                        phpgwapi_cache::session_set('logistic', 
'activity_query', $search_for);
-                                       $filters = array('project' => 
phpgw::get_var('project'), 'user' => phpgw::get_var('user'));
+                                       $filters = array('project' => 
phpgw::get_var('project'), 'user' => phpgw::get_var('user'), 'activity' => 
phpgw::get_var('filter', 'int'));
                                        $result_objects = 
$this->so->get($start_index, $num_of_objects, $sort_field, $sort_ascending, 
$search_for, $search_type, $filters);
                                        $object_count = 
$this->so->get_count($search_for, $search_type, $filters);
                                        break;




reply via email to

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