started switching so-layer to so_sql(etemplate)

created first calender hooks
This commit is contained in:
Cornelius Weiß 2005-06-11 12:59:11 +00:00
parent 7679d73df0
commit 405cdee6d1
4 changed files with 47 additions and 77 deletions

View File

@ -43,24 +43,17 @@ class bo_resources
$criteria = array( 'name' => $query['search'], $criteria = array( 'name' => $query['search'],
'short_description' => $query['search'] 'short_description' => $query['search']
); ); echo($query['filter']);
$cats = $query['filter'] ? array($query['filter'] => '') : $this->acl->get_cats(EGW_ACL_READ);
$accessory_of = $query['view_accs_of'] ? $query['view_accs_of'] : -1; $accessory_of = $query['view_accs_of'] ? $query['view_accs_of'] : -1;
$filter = array('cat_id' => ($query['filter'] ? $query['filter'] : array_flip($this->acl->get_cats(EGW_ACL_READ))),'accessory_of' => $accessory_of);
$rows = array( 0 => array( 'id' => '', $read_onlys = 'id,name,short_description,quantity,useable,bookable,buyable,cat_id,location';
'name' => '',
'short_description' => '',
'quantity' => '',
'useable' => '',
'bookable' => '',
'buyable' => '',
'cat_id' => '',
'location' => ''
));
$order_by = $query['order'] ? $query['order'].' '. $query['sort'] : ''; $order_by = $query['order'] ? $query['order'].' '. $query['sort'] : '';
$start = (int)$query['start'];
$nr = $this->so->search($criteria,$cats,$rows,$accessory_of,$order_by,$offset=$query['start'],$num_rows=0); $rows = $this->so->search($criteria,$read_onlys,$order_by,$extra_cols='',$wildcard='',$empty=False,$op='OR',$start,$filter,$join='',$need_full_no_count=false);
$nr = $this->so->total;
foreach($rows as $num => $resource) foreach($rows as $num => $resource)
{ {
@ -222,9 +215,7 @@ class bo_resources
function get_acc_list($id) function get_acc_list($id)
{ {
if($id < 1){return;} if($id < 1){return;}
$cat_id = $this->so->get_value('cat_id',$id); $data = $this->so->search('','id,name','','','','','',$start,array('accessory_of' => $id),'',$need_full_no_count=true);
$data[0] = array('id' => '', 'name' => '');
$this->so->search(array('name' => '*'),array($cat_id => ''),$data,$accessory_of=$id,$order_by='',$offset=false,$num_rows=-1);
foreach($data as $num => $resource) foreach($data as $num => $resource)
{ {
$acc_list[$resource['id']] = $resource['name']; $acc_list[$resource['id']] = $resource['name'];
@ -232,6 +223,30 @@ class bo_resources
return $acc_list; return $acc_list;
} }
/**
* returns info about resource for calender
* @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param int/array $res_id single id or array $num => $res_id
* @return array
*/
function get_calender_info($res_id)
{
if($id < 1) return;
$data[0] = array('name' => '', 'useable' => '');
foreach($res_id as $num => $id)
{
}
// $cats = array_flip($this->acl->get_cats(EGW_ACL_READ));
$this->so->search(array('name' => '*'),false,$data,-1,$order_by='',$offset=false,$num_rows=-1);
if(is_array($res_id))
{
}
return;
}
/** /**
* @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de> * @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* query infolog for entries matching $pattern * query infolog for entries matching $pattern
@ -240,10 +255,8 @@ class bo_resources
function link_query( $pattern ) function link_query( $pattern )
{ {
$criteria = array('name' => $pattern, 'short_description' => $pattern); $criteria = array('name' => $pattern, 'short_description' => $pattern);
$cats = $this->acl->get_cats(EGW_ACL_READ); $only_keys = 'id,name,short_description';
$data[0] = array('id' => '','name' => '', 'short_description' => ''); $data = $this->so->search($criteria,$only_keys,$order_by='',$extra_cols='',$wildcard='%',$empty,$op='OR');
$this->so->search($criteria,$cats,$data,$accessory_of=-1,$order_by='',$offset=false,$num_rows=-1);
foreach($data as $num => $resource) foreach($data as $num => $resource)
{ {
if($num != 0) if($num != 0)

View File

@ -3,7 +3,7 @@
* eGroupWare - resources hooks * * eGroupWare - resources hooks *
* http://www.eGroupWare.org * * http://www.eGroupWare.org *
* Originally written by Ralf Becker <RalfBecker@outdoor-training.de> * * Originally written by Ralf Becker <RalfBecker@outdoor-training.de> *
* Changes for resources by Cornelius Weiß <egw@von-und-zu-weiss.de> * * Changes for resources by Cornelius Wei<EFBFBD><egw@von-und-zu-weiss.de> *
* * * *
* ------------------------------------------------------- * * ------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
@ -76,13 +76,19 @@ class resources_hooks
} }
function search_link($args) function search_link($args)
{ {
$appname = 'resources';
return array( 'query' => 'resources.bo_resources.link_query', return array( 'query' => 'resources.bo_resources.link_query',
'title' => 'resources.bo_resources.link_title', 'title' => 'resources.bo_resources.link_title',
'view' => array('menuaction' => 'resources.ui_resources.view'), 'view' => array('menuaction' => 'resources.ui_resources.view'),
'view_id' => 'id' 'view_id' => 'id'
); );
} }
function calender_resources($args)
{
return $args['type'] =='r' ? array( 'select_template' => 'resources.resource_selectbox',
'info' => 'resources.bo_resources.get_calender_info',
) : false;
}
} }
?> ?>

View File

@ -12,68 +12,18 @@
\**************************************************************************/ \**************************************************************************/
/* $Id: */ /* $Id: */
include_once(EGW_INCLUDE_ROOT.'/etemplate/inc/class.so_sql.inc.php');
class so_resources class so_resources extends so_sql
{ {
function so_resources() function so_resources()
{ {
$this->so_sql('resources','egw_resources');
$this->db = clone($GLOBALS['egw']->db); $this->db = clone($GLOBALS['egw']->db);
$this->db->set_app('resources'); $this->db->set_app('resources');
$this->rs_table = 'egw_resources'; $this->rs_table = 'egw_resources';
} }
/**
* searches db for rows matching searchcriteria and categories
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* '*' is replaced with sql-wildcard '%'
* @param array $criteria array of key => value for search. (or'ed together)
* @param array $cats array of cat_id => cat_name to be searched
* @param &array $data reference of data array with cols to return in first row ( key => '')
* @param int $accessory_of find accessories of id, default -1 = show all exept accessories
* @param string $order_by fieldnames + {ASC|DESC} separated by colons ','
* @param int $offset row to start from, default 0
* @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']
*
* @return int number of matching rows
*/
function search($criteria,$cats,&$data,$accessory_of=-1,$order_by='',$offset=false,$num_rows=-1)
{
$select = implode(',',array_keys($data[0]));
foreach($criteria as $col => $value)
{
$where .= ($where ? " OR " : " ( " ). $col . ((strstr($value,'*') || strstr($value,'*')) ?
" LIKE '" . strtr(str_replace('_','\\_',addslashes($value)),'*?','%_') ."'":
"='" .$value."'");
}
$where .= " ) ";
foreach ((array)$cats as $cat_id => $cat_name)
{
$wherecats .= ($wherecats ? " OR " : " AND ( " ) .'cat_id' . "=".(int)$cat_id;
}
$wherecats .= $wherecats ? " ) " : "";
$whereacc = " AND (accessory_of ='".$accessory_of."')";
$this->db->query( 'SELECT '.$select." FROM ".$this->rs_table." WHERE ".$where.$wherecats.$whereacc.
($order_by != '' ? " ORDER BY $order_by" : ''),__LINE__,__FILE__);
$nr = $this->db->nf();
if($offset > 0 && $nr > $offset)
{
$this->db->seek($offset-1);
}
if($num_rows==0)
{
$num_rows = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
}
for ($n = 1; $this->db->next_record() && $n!=$num_rows+1; ++$n)
{
$data[$n] = $this->db->row();
}
unset($data[0]);
return $nr;
}
/** /**
* gets the value of $key from resource of $id * gets the value of $key from resource of $id
* *

View File

@ -33,6 +33,7 @@
$setup_info['resources']['hooks']['admin'] = 'resources.resources_hooks.admin_prefs_sidebox'; $setup_info['resources']['hooks']['admin'] = 'resources.resources_hooks.admin_prefs_sidebox';
$setup_info['resources']['hooks']['sidebox_menu'] = 'resources.resources_hooks.admin_prefs_sidebox'; $setup_info['resources']['hooks']['sidebox_menu'] = 'resources.resources_hooks.admin_prefs_sidebox';
$setup_info['resources']['hooks']['search_link'] = 'resources.resources_hooks.search_link'; $setup_info['resources']['hooks']['search_link'] = 'resources.resources_hooks.search_link';
$setup_info['resources']['hooks']['calender_resources'] = 'resources.resources_hooks.calender_resources';
// $setup_info['resources']['hooks'][] = 'home'; // $setup_info['resources']['hooks'][] = 'home';
// $setup_info['resources']['hooks'][] = 'settings'; // $setup_info['resources']['hooks'][] = 'settings';