searching and sorting with customfields using the new standard custimfield class so_sql_cf

This commit is contained in:
Stefan Becker 2009-03-23 15:23:45 +00:00
parent a2252deade
commit 3687395dab
6 changed files with 15 additions and 83 deletions

View File

@ -22,7 +22,7 @@ if (!defined('TIMESHEET_APP'))
*
* @todo Implement sorting&filtering by and searching of custom fields
*/
class timesheet_bo extends so_sql
class timesheet_bo extends so_sql_cf
{
/**
* Timesheets config data
@ -119,11 +119,10 @@ class timesheet_bo extends so_sql
function __construct()
{
parent::__construct(TIMESHEET_APP,'egw_timesheet',null,'',true); // true = use global db object!
parent::__construct(TIMESHEET_APP,'egw_timesheet',self::EXTRA_TABLE,'','ts_extra_name','ts_extra_value','ts_id');
$this->config_data = config::read(TIMESHEET_APP);
$this->quantity_sum = $this->config_data['quantity_sum'] == 'true';
$this->customfields = config::get_customfields(TIMESHEET_APP);
if($this->config_data['status_labels']) $this->status_labels =& $this->config_data['status_labels'];
$this->tz_offset_s = $GLOBALS['egw']->datetime->tz_offset;
@ -178,7 +177,7 @@ class timesheet_bo extends so_sql
if (!is_array($data))
{
$save_data = $this->data;
$data = $this->read($data,true,false); // no need to read cf's
$data = $this->read($data,true);
$this->data = $save_data;
if (!$data) return null; // entry not found
@ -370,10 +369,9 @@ class timesheet_bo extends so_sql
*
* @param int $ts_id
* @param boolean $ignore_acl=false should the acl be checked
* @param boolean $read_cfs=true also read the custom fields
* @return array/boolean array with timesheet entry, null if timesheet not found or false if no rights
*/
function read($ts_id,$ignore_acl=false,$read_cfs=true)
function read($ts_id,$ignore_acl=false)
{
//error_log(__METHOD__."($ts_id,$ignore_acl) ".function_backtrace());
if (!(int)$ts_id || (int)$ts_id != $this->data['ts_id'] && !parent::read($ts_id))
@ -384,43 +382,9 @@ class timesheet_bo extends so_sql
{
return false; // no read rights
}
if ($read_cfs && $this->customfields && ($cfs = $this->read_cfs($ts_id)))
{
$this->data += $cfs[$ts_id];
}
return $this->data;
}
/**
* Read the cf's of the given ts_id's and evtl names
*
* @param int|array $ts_ids
* @param array $names=null
* @return array with ts_id => array(name => value) pairs
*/
function read_cfs($ts_ids,$names=null)
{
//error_log(__METHOD__."(".array2string($ts_ids).",".array2string($names).")");
if (!$this->customfields || !$ts_ids)
{
return array();
}
$where = array('ts_id' => $ts_ids);
if ($names)
{
foreach($names as $name)
{
if ($name[0] == '#') $where['ts_extra_name'][] = substr($name,1);
}
}
$cfs = array();
foreach($this->db->select(self::EXTRA_TABLE,'ts_id,ts_extra_name,ts_extra_value',$where,__LINE__,__FILE__,false,'',TIMESHEET_APP) as $row)
{
$cfs[$row['ts_id']]['#'.$row['ts_extra_name']] = $row['ts_extra_value'];
}
return $cfs;
}
/**
* saves a timesheet entry
*
@ -446,22 +410,6 @@ class timesheet_bo extends so_sql
}
if (!($err = parent::save()))
{
if ($this->customfields) //saves data of custom fields in timesheet_extra
{
$this->db->delete(self::EXTRA_TABLE,array('ts_id' => $this->data['ts_id']),__LINE__,__FILE__,TIMESHEET_APP);
foreach($this->customfields as $name => $data)
{
if (isset($this->data['#'.$name]) && !empty($this->data['#'.$name]))
{
$this->db->insert(self::EXTRA_TABLE,array(
'ts_id' => $this->data['ts_id'],
'ts_extra_name' => $name,
'ts_extra_value' => $this->data['#'.$name],
),false,__LINE__,__FILE__,TIMESHEET_APP);
}
}
}
// notify the link-class about the update, as other apps may be subscribt to it
egw_link::notify_update(TIMESHEET_APP,$this->data['ts_id'],$this->data);
}
@ -489,10 +437,6 @@ class timesheet_bo extends so_sql
}
if (($ret = parent::delete($keys)) && $ts_id)
{
if ($this->customfields) //delete custom fields entries
{
$this->db->delete(self::EXTRA_TABLE,array('ts_id' => $ts_id),__LINE__,__FILE__,TIMESHEET_APP);
}
// delete all links to timesheet entry $ts_id
egw_link::unlink(0,TIMESHEET_APP,$ts_id);
}
@ -521,7 +465,7 @@ class timesheet_bo extends so_sql
return false;
}
$this->read($keys,true,false);
$this->read($keys,true);
$this->data['ts_status'] = $status;
if ($this->save($ts_id)!=0) $ret = false;
@ -595,7 +539,7 @@ class timesheet_bo extends so_sql
{
if (!is_array($entry))
{
$entry = $this->read( $entry,false,false ); // no need to read cfs
$entry = $this->read( $entry,false,false);
}
if (!$entry)
{

View File

@ -537,12 +537,6 @@ class timesheet_ui extends timesheet_bo
#_debug_array($links);
unset($query['col_filter'][0]);
// query cf's for the displayed rows
if ($ids && $this->customfields &&
in_array('customfields',$cols_to_show=explode(',',$GLOBALS['egw_info']['user']['preferences'][TIMESHEET_APP]['nextmatch-timesheet.index.rows'])))
{
$cfs = $this->read_cfs($ids,$cols_to_show);
}
$readonlys = array();
$have_cats = false;
foreach($rows as &$row)
@ -576,10 +570,6 @@ class timesheet_ui extends timesheet_bo
$row['titleClass'] = 'titleSum';
continue;
}
elseif($cfs && isset($cfs[$row['ts_id']]))
{
$row += $cfs[$row['ts_id']];
}
if (!$this->check_acl(EGW_ACL_EDIT,$row))
{
$readonlys["edit[$row[ts_id]]"] = true;

View File

@ -66,8 +66,7 @@ saves this entry and add a new one timesheet de Speichert diesen Eintrag und fü
select a price timesheet de Preis auswählen
select a project timesheet de Projekt auswählen
select a status of the timesheet timesheet de einen status auswählen
select an action or timesheet to modify timesheet de Eine Aktion auswählen
select an action or timesheet you want to modify... timesheet de Wählen Sie eine Aktion oder einen Stundenzettel aus, der geändert werden soll.
select action timesheet de Bitte eine Aktion auswählen
select multiple timeshhets for a further action timesheet de Wählen Sie mehrere Stundenzettel für einen weitere Aktion aus
show a quantity sum (eg. to sum up negative overtime) admin de Zeige eine Mengensumme (z.B. um negative Überstunden zu summieren)
start timesheet de Start

View File

@ -66,8 +66,7 @@ saves this entry and add a new one timesheet en Saves this entry and add a new o
select a price timesheet en Select a price
select a project timesheet en Select a project
select a status of the timesheet timesheet en select a status of the timesheet
select an action or timesheet to modify timesheet en Select an action or timesheet to modify
select an action or timesheet you want to modify... timesheet en Select an action or timesheet you want to modify...
select action timesheet en Select action
select multiple timeshhets for a further action timesheet en Select multiple timeshhets for a further action
show a quantity sum (eg. to sum up negative overtime) admin en Show a quantity sum (eg. to sum up negative overtime)
start timesheet en Start

File diff suppressed because one or more lines are too long

View File

@ -65,7 +65,7 @@
</vbox>
<nextmatch-filterheader id="ts_owner" options="User" no_lang="1" class="$cont[ownerClass]"/>
<nextmatch-filterheader id="ts_status" onchange="1" options="All status"/>
<nextmatch-customfields id="customfields" readonly="true"/>
<nextmatch-customfields id="customfields"/>
<hbox class="noPrint">
<description value="Actions" class="noPrint" align="right"/>
<button label="Check all" image="check" id="check_all" needed="1" statustext="Check all" onclick="toggle_all(this.form,form::name('checked[]')); return false;"/>
@ -96,7 +96,7 @@
<button image="view" label="View" id="view[$row_cont[ts_id]]" onclick="window.open(egw::link('/index.php','menuaction=timesheet.timesheet_ui.view&amp;ts_id=$row_cont[ts_id]'),'_blank','dependent=yes,width=600,height=400,scrollbars=yes,status=yes'); return false;" statustext="View this entry"/>
<button image="edit" label="Edit" id="edit[$row_cont[ts_id]]" statustext="Edit this entry" onclick="window.open(egw::link('/index.php','menuaction=timesheet.timesheet_ui.edit&amp;ts_id=$row_cont[ts_id]'),'_blank','dependent=yes,width=600,height=400,scrollbars=yes,status=yes'); return false;"/>
<button image="delete" label="Delete" id="delete[$row_cont[ts_id]]" statustext="Delete this entry" onclick="return confirm('Delete this entry');"/>
<checkbox options="$row_cont[ts_id]" id="checked[]" statustext="Select multiple contacts for a further action"/>
<checkbox options="$row_cont[ts_id]" id="checked[]" statustext="Select multiple timeshhets for a further action"/>
</hbox>
</row>
</rows>
@ -126,9 +126,9 @@
<row class="noPrint">
<button label="Add" id="add" onclick="window.open(egw::link('/index.php','menuaction=timesheet.timesheet_ui.edit'),'_blank','dependent=yes,width=600,height=400,scrollbars=yes,status=yes'); return false;"/>
<hbox align="right">
<checkbox id="use_all" label="whole query" onchange="if (this.checked==true &amp;&amp; !confirm('Apply the action on the whole query, NOT only the shown contacts!!!')) this.checked=false;" statustext="Apply the action on the whole query, NOT only the shown contacts!!!"/>
<checkbox id="use_all" label="whole query" onchange="if (this.checked==true &amp;&amp; !confirm('Apply the action on the whole query, NOT only the shown timesheets!!!')) this.checked=false;" statustext="Apply the action on the whole query, NOT only the shown timesheets!!!"/>
<menulist>
<menupopup onchange="do_action(this);" options="Select an action or timesheet you want to modify..." no_lang="1" id="action" statustext="Select an action or timesheet to modify"/>
<menupopup onchange="do_action(this);" options="Select action" id="action" statustext="Select action"/>
</menulist>
<button image="arrow_ltr" label="Check all" id="check_all" statustext="Check all" onclick="toggle_all(this.form,form::name('nm[rows][checked][]')); return false;" needed="1" class="checkAllArrow"/>
</hbox>