if db-object passed to so_sql_cf, use that also for querying custom-fields

This commit is contained in:
Ralf Becker 2015-07-27 13:17:03 +00:00
parent 310c241ca4
commit 6110c34aaa
2 changed files with 9 additions and 6 deletions

View File

@ -164,7 +164,7 @@ class so_sql_cf extends so_sql
$this->extra_join_order = " LEFT JOIN $extra_table extra_order ON $table.$this->autoinc_id=extra_order.$this->extra_id"; $this->extra_join_order = " LEFT JOIN $extra_table extra_order ON $table.$this->autoinc_id=extra_order.$this->extra_id";
$this->extra_join_filter = " JOIN $extra_table extra_filter ON $table.$this->autoinc_id=extra_filter.$this->extra_id"; $this->extra_join_filter = " JOIN $extra_table extra_filter ON $table.$this->autoinc_id=extra_filter.$this->extra_id";
$this->customfields = egw_customfields::get($app); $this->customfields = egw_customfields::get($app, false, null, $db);
} }
/** /**

View File

@ -55,9 +55,10 @@ class egw_customfields implements IteratorAggregate
* @param string $only_type2 =null if given only return fields of type2 == $only_type2 * @param string $only_type2 =null if given only return fields of type2 == $only_type2
* @param int $start =0 * @param int $start =0
* @param int $num_rows =null * @param int $num_rows =null
* @param egw_db $db =null reference to database instance to use
* @return array with customfields * @return array with customfields
*/ */
function __construct($app, $all_private_too=false, $only_type2=null, $start=0, $num_rows=null) function __construct($app, $all_private_too=false, $only_type2=null, $start=0, $num_rows=null, egw_db $db=null)
{ {
$this->app = $app; $this->app = $app;
$this->all_private_too = $all_private_too; $this->all_private_too = $all_private_too;
@ -75,7 +76,8 @@ class egw_customfields implements IteratorAggregate
{ {
$query[] = $this->commasep_match('cf_type2', $only_type2); $query[] = $this->commasep_match('cf_type2', $only_type2);
} }
$this->iterator = self::$db->select(self::TABLE, '*', $query, __LINE__, __FILE__, if (!$db) $db = self::$db;
$this->iterator = $db->select(self::TABLE, '*', $query, __LINE__, __FILE__,
!isset($num_rows) ? false : $start, 'ORDER BY cf_order ASC', 'phpgwapi', $num_rows); !isset($num_rows) ? false : $start, 'ORDER BY cf_order ASC', 'phpgwapi', $num_rows);
} }
@ -123,16 +125,17 @@ class egw_customfields implements IteratorAggregate
* @param string $app * @param string $app
* @param boolean $all_private_too =false should all the private fields be returned too, default no * @param boolean $all_private_too =false should all the private fields be returned too, default no
* @param string $only_type2 =null if given only return fields of type2 == $only_type2 * @param string $only_type2 =null if given only return fields of type2 == $only_type2
* @param egw_db $db =null reference to database to use
* @return array with customfields * @return array with customfields
*/ */
public static function get($app, $all_private_too=false, $only_type2=null) public static function get($app, $all_private_too=false, $only_type2=null, egw_db $db=null)
{ {
$cache_key = $app.':'.($all_private_too?'all':$GLOBALS['egw_info']['user']['account_id']).':'.$only_type2; $cache_key = $app.':'.($all_private_too?'all':$GLOBALS['egw_info']['user']['account_id']).':'.$only_type2;
$cfs = egw_cache::getInstance(__CLASS__, $cache_key); $cfs = egw_cache::getInstance(__CLASS__, $cache_key);
if (!isset($cfs)) if (!isset($cfs))
{ {
$cfs = iterator_to_array(new egw_customfields($app, $all_private_too, $only_type2)); $cfs = iterator_to_array(new egw_customfields($app, $all_private_too, $only_type2, 0, null, $db));
egw_cache::setInstance(__CLASS__, $cache_key, $cfs); egw_cache::setInstance(__CLASS__, $cache_key, $cfs);
$cached = egw_cache::getInstance(__CLASS__, $app); $cached = egw_cache::getInstance(__CLASS__, $app);