mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 07:53:39 +01:00
initial import of link class
This commit is contained in:
parent
66cfae907f
commit
b9f7c66d71
204
infolog/inc/class.solink.inc.php
Normal file
204
infolog/inc/class.solink.inc.php
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
<?php
|
||||||
|
/**************************************************************************\
|
||||||
|
* phpGroupWare - InfoLog Links *
|
||||||
|
* http://www.phpgroupware.org *
|
||||||
|
* Written by Ralf Becker <RalfBecker@outdoor-training.de> *
|
||||||
|
* -------------------------------------------- *
|
||||||
|
* This program is free software; you can redistribute it and/or modify it *
|
||||||
|
* under the terms of the GNU General Public License as published by the *
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
||||||
|
* option) any later version. *
|
||||||
|
\**************************************************************************/
|
||||||
|
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@class solink
|
||||||
|
@abstract generalized linking between entries of phpGroupware apps - DB layer
|
||||||
|
@discussion This class is to access the links in the DB
|
||||||
|
@note Links have to ends each pointing to an entry, an entry is a double:
|
||||||
|
@note app app-name or directory-name of an phpgw application, eg. 'infolog'
|
||||||
|
@note id this is the id, eg. an integer or a tupple like '0:INBOX:1234'
|
||||||
|
*/
|
||||||
|
class solink // DB-Layer
|
||||||
|
{
|
||||||
|
var $public_functions = array
|
||||||
|
(
|
||||||
|
'link' => True,
|
||||||
|
'get_links' => True,
|
||||||
|
'unlink' => True,
|
||||||
|
'chown' => True
|
||||||
|
);
|
||||||
|
var $db,$db2;
|
||||||
|
var $user;
|
||||||
|
var $db_name = 'phpgw_links';
|
||||||
|
var $debug = 0;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@function solink( )
|
||||||
|
@abstract constructor
|
||||||
|
*/
|
||||||
|
function solink( )
|
||||||
|
{
|
||||||
|
$this->db = $GLOBALS['phpgw']->db;
|
||||||
|
$this->user = $GLOBALS['phpgw_info']['user']['account_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@function link( $app1,$name1,$id1,$app2,$name2,$id2,$remark='',$user=0 )
|
||||||
|
@abstract creats a link between $app1,$name1,$id1 and $app2,$name2,$id2
|
||||||
|
@param $remark Remark to be saved with the link (defaults to '')
|
||||||
|
@param $owner Owner of the link (defaults to user)
|
||||||
|
@note Does NOT check if link already exists
|
||||||
|
@returns db-errno or -1 (for param-error) or 0 for success
|
||||||
|
*/
|
||||||
|
function link( $app1,$id1,$app2,$id2,$remark='',$owner=0 )
|
||||||
|
{
|
||||||
|
if ($this->debug)
|
||||||
|
echo "<p>solink.link($app1,$id1,$app2,$id2,'$remark',$owner)</p>\n";
|
||||||
|
|
||||||
|
if ($app1 == $app2 && $id1 == $id2 ||
|
||||||
|
$id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
|
||||||
|
{
|
||||||
|
return -1; // dont link to self or other nosense
|
||||||
|
}
|
||||||
|
if (!$owner)
|
||||||
|
{
|
||||||
|
$owner = $this->user;
|
||||||
|
}
|
||||||
|
$remark = $this->db->db_addslashes($remark);
|
||||||
|
$lastmod = time();
|
||||||
|
|
||||||
|
$sql = "INSERT INTO $this->db_name (link_app1,link_id1,link_app2,link_id2,link_remark,link_lastmod,link_owner) ".
|
||||||
|
" VALUES ('$app1','$id1','$app2','$id2','$remark',$lastmod,$owner)";
|
||||||
|
|
||||||
|
if ($this->debug)
|
||||||
|
{
|
||||||
|
echo "<p>solink.link($app1,$id1,$app2,$id2,'$remark',$owner) sql='$sql'</p>\n";
|
||||||
|
}
|
||||||
|
$this->db->query($sql);
|
||||||
|
|
||||||
|
return $this->db->errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@function get_links( $app,$name,$id,$only_app='',$only_name='',$order='link_lastmod DESC' )
|
||||||
|
@abstract returns array of links to $app,$name,$id
|
||||||
|
@param $only_app if set return only links from $only_app (eg. only addressbook-entries)
|
||||||
|
@param $order defaults to newest links first
|
||||||
|
@returns array of links or empty array if no matching links found
|
||||||
|
*/
|
||||||
|
function get_links( $app,$id,$only_app='',$order='link_lastmod DESC' )
|
||||||
|
{
|
||||||
|
$links = array();
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM $this->db_name".
|
||||||
|
" WHERE (link_app1 = '$app' AND link_id1 = '$id')".
|
||||||
|
" OR (link_app2 = '$app' AND link_id2 = '$id')".
|
||||||
|
($order != '' ? " ORDER BY $order" : '');
|
||||||
|
|
||||||
|
if ($this->debug)
|
||||||
|
{
|
||||||
|
echo "<p>solink.get_links($app,$id,$only_app,$order) sql='$sql'</p>\n";
|
||||||
|
}
|
||||||
|
$this->db->query($sql);
|
||||||
|
|
||||||
|
while ($this->db->next_record())
|
||||||
|
{
|
||||||
|
$row = $this->db->Record;
|
||||||
|
|
||||||
|
if ($row['link_app1'] == $app AND $row['link_id1'] == $id)
|
||||||
|
{
|
||||||
|
$link = array(
|
||||||
|
'app' => $row['link_app2'],
|
||||||
|
'id' => stripslashes($row['link_id2'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$link = array(
|
||||||
|
'app' => $row['link_app1'],
|
||||||
|
'id' => stripslashes($row['link_id1'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($only_app != '' && $link['app'] != $only_app)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$link['remark'] = stripslashes($row['link_remark']);
|
||||||
|
$link['owner'] = $row['link_owner'];
|
||||||
|
$link['lastmod'] = $row['link_lastmod'];
|
||||||
|
$link['link_id'] = $row['link_id'];
|
||||||
|
|
||||||
|
$links[] = $link;
|
||||||
|
}
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@function unlink($link_id,$app='',$id='',$owner='')
|
||||||
|
@abstract Remove link with $link_id or all links matching given params
|
||||||
|
@param $link_id link-id to remove if > 0
|
||||||
|
@param $app,$id,$owner if $link_id <= 0: removes all links matching the non-empty params
|
||||||
|
@returns the number of links deleted
|
||||||
|
*/
|
||||||
|
function unlink($link_id,$app='',$id='',$owner='')
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM $this->db_name WHERE ";
|
||||||
|
if ($link_id > 0)
|
||||||
|
{
|
||||||
|
$sql .= "link_id=$link_id";
|
||||||
|
}
|
||||||
|
elseif ($app == '' AND $owner == '')
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($app != '')
|
||||||
|
{
|
||||||
|
$sql .= "((link_app1='$app'";
|
||||||
|
$sql2 = '';
|
||||||
|
if ($id != '')
|
||||||
|
{
|
||||||
|
$sql .= " AND link_id1='$id'";
|
||||||
|
$sql2 .= " AND link_id2='$id'";
|
||||||
|
}
|
||||||
|
$sql .= ") OR (link_app2='$app'$sql2))";
|
||||||
|
}
|
||||||
|
if ($owner != '')
|
||||||
|
{
|
||||||
|
$sql .= ($app != '' ? ' AND ' : '') . "link_owner='$owner'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->debug)
|
||||||
|
{
|
||||||
|
echo "<p>solink.unlink($link_id,$app,$id,$owner) sql='$sql'</p>\n";
|
||||||
|
}
|
||||||
|
$this->db->query($sql);
|
||||||
|
|
||||||
|
return $this->db->affected_rows();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@function chown($owner,$new_owner)
|
||||||
|
@abstract Changes ownership of all links from $owner to $new_owner
|
||||||
|
@discussion This is needed when a user/account gets deleted
|
||||||
|
@note Does NOT change the modification-time
|
||||||
|
@returns the number of links changed
|
||||||
|
*/
|
||||||
|
function chown($owner,$new_owner)
|
||||||
|
{
|
||||||
|
if ($owner <= 0 || $new_owner <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
$this->db->query("UPDATE $this->db_name SET owner=$new_owner WHERE owner=$owner");
|
||||||
|
|
||||||
|
return $this->db->affected_rows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -41,5 +41,21 @@
|
|||||||
'fk' => array(),
|
'fk' => array(),
|
||||||
'ix' => array(),
|
'ix' => array(),
|
||||||
'uc' => array()
|
'uc' => array()
|
||||||
|
),
|
||||||
|
'phpgw_links' => array(
|
||||||
|
'fd' => array(
|
||||||
|
'link_id' => array('type' => 'auto','nullable' => False),
|
||||||
|
'link_app1' => array('type' => 'varchar','precision' => '25','nullable' => False),
|
||||||
|
'link_id1' => array('type' => 'varchar','precision' => '50','nullable' => False),
|
||||||
|
'link_app2' => array('type' => 'varchar','precision' => '25','nullable' => False),
|
||||||
|
'link_id2' => array('type' => 'varchar','precision' => '50','nullable' => False),
|
||||||
|
'link_remark' => array('type' => 'varchar','precision' => '50','nullable' => True),
|
||||||
|
'link_lastmod' => array('type' => 'int','precision' => '4','nullable' => False),
|
||||||
|
'link_owner' => array('type' => 'int','precision' => '4','nullable' => False)
|
||||||
|
),
|
||||||
|
'pk' => array('link_id'),
|
||||||
|
'fk' => array(),
|
||||||
|
'ix' => array(),
|
||||||
|
'uc' => array()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -26,4 +26,30 @@
|
|||||||
$GLOBALS['setup_info']['infolog']['currentver'] = '0.9.15.001';
|
$GLOBALS['setup_info']['infolog']['currentver'] = '0.9.15.001';
|
||||||
return $GLOBALS['setup_info']['phpgwapi']['currentver'];
|
return $GLOBALS['setup_info']['phpgwapi']['currentver'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$test[] = '0.9.15.001';
|
||||||
|
function infolog_upgrade0_9_15_001()
|
||||||
|
{
|
||||||
|
$GLOBALS['phpgw_setup']->oProc->CreateTable('phpgw_links',array(
|
||||||
|
'fd' => array(
|
||||||
|
'link_id' => array('type' => 'auto','nullable' => False),
|
||||||
|
'link_app1' => array('type' => 'varchar','precision' => '25','nullable' => False),
|
||||||
|
'link_id1' => array('type' => 'varchar','precision' => '50','nullable' => False),
|
||||||
|
'link_app2' => array('type' => 'varchar','precision' => '25','nullable' => False),
|
||||||
|
'link_id2' => array('type' => 'varchar','precision' => '50','nullable' => False),
|
||||||
|
'link_remark' => array('type' => 'varchar','precision' => '50','nullable' => True),
|
||||||
|
'link_lastmod' => array('type' => 'int','precision' => '4','nullable' => False),
|
||||||
|
'link_owner' => array('type' => 'int','precision' => '4','nullable' => False)
|
||||||
|
),
|
||||||
|
'pk' => array('link_id'),
|
||||||
|
'fk' => array(),
|
||||||
|
'ix' => array(),
|
||||||
|
'uc' => array()
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
$GLOBALS['setup_info']['infolog']['currentver'] = '0.9.15.002';
|
||||||
|
return $GLOBALS['setup_info']['phpgwapi']['currentver'];
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user