<?php

Doo::loadModel('uprofile');

class Profile
{

    private $uprofile;

    public function __construct()
    {
        $this->uprofile = new Uprofile();
    }

    public function insertProfile($intp = array())
    {
        if (!isset($intp['userid']))
            return FALSE;
        $this->uprofile->userid = filter_var($intp['userid'], FILTER_VALIDATE_INT);
        $this->uprofile->name = filter_var($intp['realname'], FILTER_SANITIZE_STRING);
        $this->uprofile->company = filter_var($intp['company'], FILTER_SANITIZE_STRING);
        $this->uprofile->jobs = filter_var($intp['jobs'], FILTER_SANITIZE_STRING);
        $this->uprofile->remark = filter_var($intp['remark'], FILTER_SANITIZE_STRING);
        $this->uprofile->phone = filter_var($intp['phone'], FILTER_SANITIZE_STRING);
//        $this->uprofile->mobile = filter_var($intp['mobile'], FILTER_SANITIZE_STRING);
        if (isset($intp['qq']))
            $this->uprofile->qq = filter_var($intp['qq'], FILTER_SANITIZE_STRING);
        $this->uprofile->groups = 'vip';
        return $this->uprofile->insert();
    }

    public function ZGinsertProfile($uid = 0, $realname)
    {
        if (!isset($uid))
            return FALSE;
        $this->uprofile->userid = $uid;
        $this->uprofile->name = $realname;
        $this->uprofile->company = '';
        $this->uprofile->jobs = '';
        $this->uprofile->phone = '';
        $this->uprofile->mobile = '';
        $this->uprofile->qq = '';
        $this->uprofile->groups = 'vip';
        return $this->uprofile->insert();
    }

    public function getProWithUid($userid = 0)
    {
        if (!isset($userid))
            return FALSE;
        return $this->uprofile->getOne(array('where' => 'userid=?', 'param' => array($userid), 'asArray' => TRUE));
    }

    public function getVerifiedMobile($userid = 0)
    {
        if (!isset($userid))
            return FALSE;
        return $this->uprofile->getOne(array('where' => 'userid=? and isnotice=1', 'param' => array($userid), 'asArray' => TRUE));
    }

    public function setAvatar($userid = 0, $avaurl)
    {
        if (!isset($userid))
            return FALSE;
        $this->uprofile->avatar = $avaurl;
        return $this->uprofile->update(array('where' => 'userid=?', 'param' => array($userid)));
    }

    public function setSignPath($userid = 0, $avaurl)
    {
        if (!isset($userid))
            return FALSE;
        $this->uprofile->signpath = $avaurl;
        return $this->uprofile->update(array('where' => 'userid=?', 'param' => array($userid)));
    }

    public function upProfile($userid, $proArray)
    {
        $this->uprofile->name = $proArray['name'];
        $this->uprofile->company = $proArray['company'];
        $this->uprofile->jobs = $proArray['jobs'];
        $this->uprofile->remark = $proArray['remark'];
        $this->uprofile->phone = $proArray['phone'];
        $this->uprofile->mobile = $proArray['mobile'];
        if (isset($proArray['qq']) && $proArray['qq'])
            $this->uprofile->qq = $proArray['qq'];
        return $this->uprofile->update(array('where' => 'userid=?', 'param' => array($userid)));
    }

    public function updateMobile($userid, $mobile)
    {
        $this->uprofile->mobile = $mobile;
        $this->uprofile->isnotice = 1;
        return $this->uprofile->update(array('where' => 'userid=?', 'param' => array($userid)));
    }

    public function checkMobile($number)
    {
        return $this->uprofile->count(array('where' => 'mobile=?', 'param' => array($number), 'asArray' => TRUE));
    }
}

?>