<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
*/
!defined('IN_MUDDER') && exit('Access Denied');
class moFriendModel {
    var $db = null;
    var $tablename = 'friends';

    function moFriendModel() {
        global $db,$dbpre;

        $this->db = &$db;
        $this->tablename = $dbpre.$this->tablename;
    }

    function getTotal($uid) {
        return $this->db->get_value("SELECT COUNT(*) FROM {$this->tablename} WHERE uid='$uid'");
    }

    function & read($uid, $limit) {
        global $dbpre;
        if(is_numeric($limit) && $limit>0) {
            $limit = "0, $limit";
        } elseif(is_array($limit)&&count($limit)==2) {
            $limit = $limit[0].",".$limit[1];
        } else {
            $limit = "0,10";
        }
        $query = $this->db->query("SELECT m.face,m.point,f.fuid,f.fusername FROM {$dbpre}members m LEFT JOIN {$this->tablename} f ON(m.uid=f.fuid) WHERE f.uid='$uid' ORDER BY addtime DESC LIMIT $limit");
        while($row=$this->db->fetch_array($query)) {
            
            $row['face'] = get_face($row['face']);
            $row['rank'] = get_userrank($row['point']);
            $result[] = $row;
        }
        if(empty($result)) $result = array();
        return $result;
    }

    function add(& $post) {
    }

    function delete($uids) {
    }
}
?>