move categories class to api

This commit is contained in:
Ralf Becker 2016-03-20 13:41:33 +00:00
parent 52a7f2198a
commit 4da844a70f
11 changed files with 1175 additions and 1132 deletions

View File

@ -622,7 +622,7 @@ class Accounts
$GLOBALS['egw']->acl->delete_account($id); $GLOBALS['egw']->acl->delete_account($id);
// delete all categories belonging to that user or group // delete all categories belonging to that user or group
categories::delete_account($id); Categories::delete_account($id);
return true; return true;
} }

1154
api/src/Categories.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -16,10 +16,6 @@
namespace EGroupware\Api; namespace EGroupware\Api;
// explicitly reference classes still in phpgwapi
use categories;
use etemplate; // cats2color
use calendar_bo; // to_do: do NOT require it, just use if there use calendar_bo; // to_do: do NOT require it, just use if there
/** /**
@ -143,7 +139,7 @@ class Contacts extends Contacts\Storage
/** /**
* Categories object * Categories object
* *
* @var categories * @var Categories
*/ */
var $categories; var $categories;
@ -315,7 +311,7 @@ class Contacts extends Contacts\Storage
$this->org_fields[] = 'adr_two_countrycode'; $this->org_fields[] = 'adr_two_countrycode';
} }
} }
$this->categories = new categories($this->user,'addressbook'); $this->categories = new Categories($this->user,'addressbook');
$this->delete_history = $GLOBALS['egw_info']['server']['history']; $this->delete_history = $GLOBALS['egw_info']['server']['history'];
} }
@ -1525,7 +1521,7 @@ class Contacts extends Contacts\Storage
$result[$contact['id']] = call_user_func_array('imap_rfc822_write_address', $args); $result[$contact['id']] = call_user_func_array('imap_rfc822_write_address', $args);
} }
// show category color // show category color
if ($contact['cat_id'] && ($color = etemplate::cats2color($contact['cat_id']))) if ($contact['cat_id'] && ($color = Categories::cats2color($contact['cat_id'])))
{ {
$result[$contact['id']] = array( $result[$contact['id']] = array(
'label' => $result[$contact['id']], 'label' => $result[$contact['id']],
@ -1691,7 +1687,7 @@ class Contacts extends Contacts\Storage
$drop_subs = ($data['drop_subs'] && !$data['modify_subs']); $drop_subs = ($data['drop_subs'] && !$data['modify_subs']);
if($drop_subs) if($drop_subs)
{ {
$cats = new categories('', 'addressbook'); $cats = new Categories('', 'addressbook');
$cat_ids = $cats->return_all_children($data['cat_id']); $cat_ids = $cats->return_all_children($data['cat_id']);
} }
else else
@ -2090,7 +2086,7 @@ class Contacts extends Contacts\Storage
{ {
if (!is_object($this->categories)) if (!is_object($this->categories))
{ {
$this->categories = new categories($this->user,'addressbook'); $this->categories = new Categories($this->user,'addressbook');
} }
if (!is_array($cat_id_list)) if (!is_array($cat_id_list))

View File

@ -932,7 +932,7 @@ class Ldap
{ {
if (!is_object($GLOBALS['egw']->categories)) if (!is_object($GLOBALS['egw']->categories))
{ {
$GLOBALS['egw']->categories = CreateObject('phpgwapi.categories'); $GLOBALS['egw']->categories = new Api\Categories();
} }
$cats = $GLOBALS['egw']->categories->return_all_children((int)$value); $cats = $GLOBALS['egw']->categories->return_all_children((int)$value);
if (count($cats) > 1) $filters .= '(|'; if (count($cats) > 1) $filters .= '(|';
@ -1210,7 +1210,7 @@ class Ldap
foreach(is_array($data['cat_id']) ? $data['cat_id'] : explode(',',$data['cat_id']) as $cat) foreach(is_array($data['cat_id']) ? $data['cat_id'] : explode(',',$data['cat_id']) as $cat)
{ {
$ldapContact['category'][] = Api\Translation::convert( $ldapContact['category'][] = Api\Translation::convert(
ExecMethod('phpgwapi.categories.id2name',$cat),$this->charset,'utf-8'); Api\Categories::id2name($cat),$this->charset,'utf-8');
} }
} }
foreach(array( foreach(array(
@ -1256,7 +1256,7 @@ class Ldap
{ {
if (!is_int($iii)) continue; if (!is_int($iii)) continue;
$contact['cat_id'][] = ExecMethod('phpgwapi.categories.name2id',$cat); $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat);
} }
if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']);
} }

View File

@ -439,7 +439,7 @@ class Sql extends Api\Storage
{ {
if (!is_object($GLOBALS['egw']->categories)) if (!is_object($GLOBALS['egw']->categories))
{ {
$GLOBALS['egw']->categories = CreateObject('phpgwapi.categories'); $GLOBALS['egw']->categories = new Api\Categories;
} }
foreach($GLOBALS['egw']->categories->return_all_children((int)$cat_id) as $cat) foreach($GLOBALS['egw']->categories->return_all_children((int)$cat_id) as $cat)
{ {

View File

@ -16,7 +16,6 @@ namespace EGroupware\Api;
// explicitly import old not yet ported classes // explicitly import old not yet ported classes
use egw; use egw;
use egw_framework; use egw_framework;
use categories; // css
/** /**
* New eTemplate serverside contains: * New eTemplate serverside contains:
@ -232,7 +231,7 @@ class Etemplate extends Etemplate\Widget\Template
egw_framework::validate_file('.','app',$app,false); egw_framework::validate_file('.','app',$app,false);
} }
// Category styles // Category styles
categories::css($app); Categories::css($app);
// set action attribute for autocomplete form tag // set action attribute for autocomplete form tag
// as firefox complains on about:balnk action, thus we have to literaly submit the form to a blank html // as firefox complains on about:balnk action, thus we have to literaly submit the form to a blank html

View File

@ -19,7 +19,6 @@ use EGroupware\Api;
// explicitly import old not yet ported classes // explicitly import old not yet ported classes
use egw; use egw;
use egw_framework; // includeCSS use egw_framework; // includeCSS
use categories;
/** /**
* eTemplate serverside implementation of the nextmatch widget * eTemplate serverside implementation of the nextmatch widget
@ -920,7 +919,7 @@ class Nextmatch extends Etemplate\Widget
public static function category_action($app, $group=0, $caption='Change category', public static function category_action($app, $group=0, $caption='Change category',
$prefix='cat_', $globals=true, $parent_id=0, $max_cats_flat=self::DEFAULT_MAX_MENU_LENGTH) $prefix='cat_', $globals=true, $parent_id=0, $max_cats_flat=self::DEFAULT_MAX_MENU_LENGTH)
{ {
$cat = new categories(null,$app); $cat = new Api\Categories(null,$app);
$cats = $cat->return_sorted_array($start=0, false, '', 'ASC', 'cat_name', $globals, $parent_id, true); $cats = $cat->return_sorted_array($start=0, false, '', 'ASC', 'cat_name', $globals, $parent_id, true);
// if more then max_length cats, switch automatically to hierarchical display // if more then max_length cats, switch automatically to hierarchical display

View File

@ -17,7 +17,6 @@ use EGroupware\Api\Etemplate;
use EGroupware\Api; use EGroupware\Api;
// explicitly import old not yet ported classes // explicitly import old not yet ported classes
use categories;
use calendar_timezones; use calendar_timezones;
/** /**
@ -563,7 +562,7 @@ class Select extends Etemplate\Widget
} }
else // we need to instanciate a new cat object for the correct application else // we need to instanciate a new cat object for the correct application
{ {
$categories = new categories($type5,$type3); $categories = new Api\Categories($type5,$type3);
} }
// Allow text for global // Allow text for global
$type = ($type && strlen($type) > 1 ? $type : !$type); $type = ($type && strlen($type) > 1 ? $type : !$type);
@ -572,9 +571,9 @@ class Select extends Etemplate\Widget
{ {
$s = str_repeat(' ',$cat['level']) . stripslashes($cat['name']); $s = str_repeat(' ',$cat['level']) . stripslashes($cat['name']);
if (categories::is_global($cat)) if (Api\Categories::is_global($cat))
{ {
$s .= categories::$global_marker; $s .= Api\Categories::$global_marker;
} }
$options[$cat['id']] = array( $options[$cat['id']] = array(
'label' => $s, 'label' => $s,

View File

@ -18,7 +18,6 @@ use EGroupware\Api;
// explicitly import old not yet ported classes // explicitly import old not yet ported classes
use common; // egw_exit use common; // egw_exit
use categories;
use egw_framework; use egw_framework;
egw_framework::includeCSS('/phpgwapi/js/dhtmlxtree/codebase/dhtmlXTree.css'); egw_framework::includeCSS('/phpgwapi/js/dhtmlxtree/codebase/dhtmlXTree.css');
@ -436,7 +435,7 @@ class Tree extends Etemplate\Widget
} }
else // we need to instanciate a new cat object for the correct application else // we need to instanciate a new cat object for the correct application
{ {
$categories = new categories('',$type3); $categories = new Api\Categories('',$type3);
} }
$cat2path=array(); $cat2path=array();
foreach((array)$categories->return_sorted_array(0,False,'','','',!$type,0,true) as $cat) foreach((array)$categories->return_sorted_array(0,False,'','','',!$type,0,true) as $cat)

View File

@ -712,33 +712,7 @@ class etemplate extends boetemplate
*/ */
static function cats2color($cats) static function cats2color($cats)
{ {
static $cat2color; return Api\Categories::cats2color($cats);
// ACL check
$cats = $GLOBALS['egw']->categories->check_list(EGW_ACL_READ,$cats);
if (!$cats) return null;
if (isset($cat2color[$cats]))
{
return $cat2color[$cats];
}
foreach(explode(',',$cats) as $cat)
{
if (isset($cat2color[$cat]))
{
return $cat2color[$cat];
}
$data = categories::id2name($cat,'data');
if (is_array($data) && ($color = $data['color']))
{
//echo "<p>cats2color('$cats')=$color</p>\n";
return $cat2color[$cats] = $cat2color[$cat] = $color;
}
}
return null;
} }
/** /**

File diff suppressed because it is too large Load Diff