<?php
/**
 * 
 * @file user_relations.php
 * @copyright (c) 2005 - 2011 eifr.com
 * @license http://www.gnu.org/copyleft/gpl.html gnu/gpl
 * eifr is free software
 */

class ComUserRelations {
    var $types = array('employee', 'leader', 'friend');

    public static function deleteRecordByid($id) {
        return dbDelete(TB_USER_RELATIONS, "id='$id'");
    } 

    public static function deleteRecordsByUid($uid) {
        return dbDelete(TB_USER_RELATIONS, "uid='$uid'");
    } 

    public static function deleteRecordsByRuid($ruid) {
        return dbDelete(TB_USER_RELATIONS, "ruid='$ruid'");
    } 

    public static function deleteRecordByUidAndRuid($uid, $ruid) {
        return dbDelete(TB_USER_RELATIONS, "uid='$uid' and ruid='$ruid'");
    } 

    public static function addRecordByUidAndRuid($uid, $ruid, $type = 0) {
        $record_arr = array();
        $record_arr['uid'] = $uid;
        $record_arr['ruid'] = $ruid;
        $record_arr['type'] = $type;
        return dbInsert(TB_USER_RELATIONS, $record_arr);
    } 

    public static function editTypeByUidAndRuid($uid, $ruid, $type = 0) {
        $record_arr = array();
        $record_arr['type'] = $type;
        return dbUpdate(TB_USER_RELATIONS, $record_arr, "uid='$uid' and ruid='$ruid'");
    } 

    public static function getRelationUsersByUid($uid) {
        $sql = "select ur.*, u.username, u.nickname, u.realname from " . TB_USER_RELATIONS . " as ur left join " . TB_USER . " as u on ur.ruid=u.uid where ur.uid='$uid'";
        return dbGetRecord1($sql);
    } 
} 

?>