2005-02-03 17:42:20 +01:00
|
|
|
<?php
|
2005-11-11 00:35:55 +01:00
|
|
|
/**
|
2011-10-14 10:36:12 +02:00
|
|
|
* EGroupware - resources
|
2005-11-11 00:35:55 +01:00
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package resources
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
|
|
|
* @author Lukas Weiss <wnz_gh05t@users.sourceforge.net>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
/**
|
|
|
|
* General storage object for resources
|
|
|
|
*
|
2005-11-14 19:16:56 +01:00
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
2005-11-09 22:03:35 +01:00
|
|
|
* @package resources
|
|
|
|
*/
|
2011-03-23 16:25:59 +01:00
|
|
|
class resources_so extends so_sql_cf
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2011-03-23 16:25:59 +01:00
|
|
|
function __construct()
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2011-03-23 16:25:59 +01:00
|
|
|
parent::__construct('resources','egw_resources', 'egw_resources_extra', '',
|
|
|
|
'extra_name', 'extra_value', 'extra_id' );
|
2010-04-01 22:57:15 +02:00
|
|
|
|
|
|
|
$this->columns_to_search = array('name','short_description','inventory_number','long_description','location');
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
2005-06-29 11:30:08 +02:00
|
|
|
* gets the value of $key from resource of $res_id
|
2005-06-10 22:40:57 +02:00
|
|
|
*
|
|
|
|
* @param string $key key of value to get
|
2005-06-29 11:30:08 +02:00
|
|
|
* @param int $res_id resource id
|
2005-06-10 22:40:57 +02:00
|
|
|
* @return mixed value of key and resource, false if key or id not found.
|
|
|
|
*/
|
2005-06-29 11:30:08 +02:00
|
|
|
function get_value($key,$res_id)
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2011-10-14 10:36:12 +02:00
|
|
|
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();
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2008-10-25 07:25:52 +02:00
|
|
|
|
2005-11-14 19:16:56 +01:00
|
|
|
/**
|
|
|
|
* reads resource including custom fields
|
|
|
|
*
|
2011-10-14 10:36:12 +02:00
|
|
|
* 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
|
2005-11-14 19:16:56 +01:00
|
|
|
*/
|
|
|
|
function read($res_id)
|
|
|
|
{
|
2011-10-14 10:36:12 +02:00
|
|
|
if (is_array($res_id) && count($res_id) == 1 && isset($res_id['res_id'])) $res_id = $res_id['res_id'];
|
2008-10-25 07:25:52 +02:00
|
|
|
|
2011-10-14 10:36:12 +02:00
|
|
|
/*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;
|
2005-11-14 19:16:56 +01:00
|
|
|
}
|
2005-02-17 16:27:43 +01:00
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
2005-11-14 19:16:56 +01:00
|
|
|
* saves a resource including extra fields
|
|
|
|
*
|
2008-10-25 07:25:52 +02:00
|
|
|
* @param array $resource key => value
|
2005-11-14 19:16:56 +01:00
|
|
|
* @return mixed id of resource if all right, false if fale
|
2005-06-10 22:40:57 +02:00
|
|
|
*/
|
2005-02-12 16:49:38 +01:00
|
|
|
function save($resource)
|
|
|
|
{
|
2005-06-13 14:21:18 +02:00
|
|
|
$this->data = $resource;
|
2005-11-14 19:16:56 +01:00
|
|
|
if(parent::save() != 0) return false;
|
|
|
|
$res_id = $this->data['res_id'];
|
2008-10-25 07:25:52 +02:00
|
|
|
|
2005-11-14 19:16:56 +01:00
|
|
|
return $res_id;
|
2005-02-12 16:49:38 +01:00
|
|
|
}
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|