diff --git a/resources/inc/class.resources_bo.inc.php b/resources/inc/class.resources_bo.inc.php index f9cef05ad1..207a555ee9 100755 --- a/resources/inc/class.resources_bo.inc.php +++ b/resources/inc/class.resources_bo.inc.php @@ -1,6 +1,6 @@ get_picture($resource['res_id']); + $rows[$num]['picture_thumb'] = $this->get_picture($resource); $rows[$num]['admin'] = $this->acl->get_cat_admin($resource['cat_id']); } return $nr; @@ -627,21 +627,18 @@ class resources_bo /** * get resource picture either from vfs or from symlink * Cornelius Weiss - * @param int $res_id id of resource + * @param int|array $resource res-id or whole resource array * @param bool $fullsize false = thumb, true = full pic * @return string url of picture */ - function get_picture($res_id=0,$fullsize=false) + function get_picture($resource,$fullsize=false) { - if ($res_id > 0) - { - $src = $this->so->get_value('picture_src',$res_id); - } -#echo $scr."
". $this->pictures_dir."
"; - switch($src) + if ($resource && !is_array($resource)) $resource = $this->read($resource); + + switch($resource['picture_src']) { case 'own_src': - $picture = egw_link::vfs_path('resources',$res_id,self::PICTURE_NAME,true); // vfs path + $picture = egw_link::vfs_path('resources',$resource['res_id'],self::PICTURE_NAME,true); // vfs path if ($fullsize) { $picture = egw::link(egw_vfs::download_url($picture)); @@ -650,17 +647,17 @@ class resources_bo { $picture = egw::link('/etemplate/thumbnail.php',array('path' => $picture)); } - //$picture=$GLOBALS['egw_info']['server'].$picture; -#echo $picture."
"; break; + case 'cat_src': - list($picture) = $this->cats->return_single($this->so->get_value('cat_id',$res_id)); + list($picture) = $this->cats->return_single($resource['cat_id']); $picture = unserialize($picture['data']); if($picture['icon']) { $picture = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/images/'.$picture['icon']; break; } + // fall through case 'gen_src': default : $picture = $GLOBALS['egw_info']['server']['webserver_url'].$this->resource_icons; @@ -670,7 +667,6 @@ class resources_bo } /** - * remove_picture * removes picture from vfs * * Cornelius Weiss diff --git a/resources/inc/class.resources_so.inc.php b/resources/inc/class.resources_so.inc.php index 286d6d3b58..f2d1f65357 100755 --- a/resources/inc/class.resources_so.inc.php +++ b/resources/inc/class.resources_so.inc.php @@ -1,6 +1,6 @@ db->select($this->table_name,$key,array('res_id' => $res_id),__LINE__,__FILE__)->fetchColumn(); + return $res_id == $this->data['res_id'] ? $this->data[$key] : + $this->db->select($this->table_name,$key,array('res_id' => $res_id),__LINE__,__FILE__)->fetchColumn(); } /** * reads resource including custom fields * - * @param interger $res_id res_id - * @return array/boolean data if row could be retrived else False + * Reimplemented to do some minimal caching (re-use already read data) + * + * @param int|array $res_id res_id + * @return array|boolean data if row could be retrived else False */ function read($res_id) { - // read main data - $resource = parent::read($res_id); + if (is_array($res_id) && count($res_id) == 1 && isset($res_id['res_id'])) $res_id = $res_id['res_id']; - return $resource; + /*if (!is_array($res_id) && $res_id == $this->data['res_id']) + { + error_log(__METHOD__.'('.array2string($res_id).') this->data[res_id]='.array2string($this->data['res_id']).' --> returning this->data'); + } + else + { + error_log(__METHOD__.'('.array2string($res_id).') this->data[res_id]='.array2string($this->data['res_id']).' --> returning parent::read()'); + }*/ + return !is_array($res_id) && $res_id == $this->data['res_id'] ? $this->data : parent::read($res_id); + } + + /** + * deletes resource + * + * Reimplemented to do some minimal caching (re-use already read data) + * + * @param int|array $res_id id of resource + * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids + */ + function delete($res_id) + { + if (($ok = parent::delete($res_id)) && !is_array($res_id) && $res_id == $this->data['res_id']) + { + unset($this->data); + } + return $ok; } /** @@ -66,5 +93,4 @@ class resources_so extends so_sql_cf return $res_id; } - }