Move constructor to the top of the class; Use one db object instead of two;

Do the query in return_array() only once; Make formated_list() a wrapper to
formatted_list();
This commit is contained in:
Miles Lott 2002-01-03 17:16:56 +00:00
parent 61a2d639f0
commit 7c92b70b90

View File

@ -36,6 +36,28 @@
var $total_records;
var $grants;
/*!
@function categories
@abstract constructor for categories class
@param $accountid account id
@param $app_name app name defaults to current app
*/
function categories($accountid = '',$app_name = '')
{
$account_id = get_account_id($accountid);
if (! $app_name)
{
$app_name = $GLOBALS['phpgw_info']['flags']['currentapp'];
}
$this->account_id = $account_id;
$this->app_name = $app_name;
$this->db = $GLOBALS['phpgw']->db;
$this->grants = $GLOBALS['phpgw']->acl->get_grants($app_name);
$this->cats = $this->return_array($type,$start,$limit,$query,$sort,$order,$public);
}
/*!
@function filter
@abstract ?
@ -54,6 +76,7 @@
}
return $s;
}
/*!
@function total
@abstract returns the total number of categories for app, subs or mains
@ -112,7 +135,6 @@
$ordermethod = ' ORDER BY cat_main, cat_level, cat_name ASC';
}
if (is_array($this->grants))
{
$grants = $this->grants;
@ -141,10 +163,6 @@
$sql = "SELECT * from phpgw_categories WHERE (cat_appname='" . $this->app_name . "' AND" . $grant_cats . $public_cats . ")"
. $parent_filter . $querymethod . $filter;
$this->db2->query($sql,__LINE__,__FILE__);
$this->total_records = $this->db2->num_rows();
if ($limit)
{
$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
@ -154,6 +172,8 @@
$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
}
$this->total_records = $this->db->num_rows();
$i = 0;
while ($this->db->next_record())
{
@ -197,49 +217,9 @@
}
return $cats;
}
/*!
@function categories
@abstract constructor for categories class
@param $accountid account id
@param $app_name app name defaults to current app
*/
function categories($accountid = '',$app_name = '')
{
$account_id = get_account_id($accountid);
if (! $app_name)
{
$app_name = $GLOBALS['phpgw_info']['flags']['currentapp'];
}
$this->account_id = $account_id;
$this->app_name = $app_name;
$this->db = $GLOBALS['phpgw']->db;
$this->db2 = $this->db;
$this->total_records = $this->db2->num_rows();
$this->grants = $GLOBALS['phpgw']->acl->get_grants($app_name);
$this->cats = $this->return_array($type,$start,$limit,$query,$sort,$order,$public);
}
function in_array($needle,$haystack)
{
if (function_exists('in_array'))
{
return in_array($needle,$haystack);
}
while (list ($k,$v) = each($haystack))
{
if ($v == $needle)
{
return True;
}
}
return False;
}
// Return into a select box, list or other formats
/*!
@function formated_list
@function formatted_list
@abstract return into a select box, list or other formats
@param $format currently only supports select (select box)
@param $type string - subs or mains
@ -247,6 +227,10 @@
@result $s array - populated with categories
*/
function formated_list($format,$type,$selected = '',$public = False,$site_link = 'site')
{
return $this->formatted_list($format,$type,$selected,$public,$site_link);
}
function formatted_list($format,$type,$selected = '',$public = False,$site_link = 'site')
{
if(is_array($format))
{
@ -274,7 +258,7 @@
for ($i=0;$i<count($cats);$i++)
{
$s .= '<option value="' . $cats[$i]['id'] . '"';
if ($this->in_array($cats[$i]['id'],$selected))
if (in_array($cats[$i]['id'],$selected))
{
$s .= ' selected';
}
@ -294,8 +278,6 @@
$cats = $this->return_array($type,$start,False,$query,$sort,$order,$public);
$this->total_records = $this->db2->num_rows();
$s = '<table border="0" cellpadding="2" cellspacing="2">' . "\n";
if ($this->total_records > 0)
@ -304,12 +286,12 @@
{
$image_set = '&nbsp;';
if ($this->in_array($cats[$i]['id'],$selected))
if (in_array($cats[$i]['id'],$selected))
{
$image_set = '<img src="' . PHPGW_IMAGES_DIR . '/roter_pfeil.gif">';
}
if (($cats[$i]['level'] == 0) && !$this->in_array($cats[$i]['id'],$selected))
if (($cats[$i]['level'] == 0) && !in_array($cats[$i]['id'],$selected))
{
$image_set = '<img src="' . PHPGW_IMAGES_DIR . '/grauer_pfeil.gif">';
}
@ -355,10 +337,11 @@
if (!$cat_values['parent'] || $cat_values['parent'] == 0)
{
$this->db2->query("SELECT MAX(cat_id) AS max FROM phpgw_categories",__LINE__,__FILE__);
$this->db2->next_record();
$this->db->query("UPDATE phpgw_categories SET cat_main='" . $this->db2->f('max') . "' WHERE cat_id='"
. $this->db2->f('max') . "'",__LINE__,__FILE__);
$this->db->query("SELECT MAX(cat_id) AS max FROM phpgw_categories",__LINE__,__FILE__);
$this->db->next_record();
$max = $this->db->f('max');
$this->db->query("UPDATE phpgw_categories SET cat_main='" . $max . "' WHERE cat_id='"
. $max . "'",__LINE__,__FILE__);
}
}
@ -377,6 +360,7 @@
$this->db->query("DELETE FROM phpgw_categories WHERE cat_id='$cat_id' $subdelete AND cat_appname='"
. $this->app_name . "'",__LINE__,__FILE__);
}
/*!
@function edit
@abstract edit a category