<?php

namespace Community\Lib;

use Dever;

class Comment
{
    public function getData($method = 'getAll', $uid, $type = false, $type_id = false, $user = false, $collection_id = false)
    {
        $where['type'] = $type;
        $where['type_id'] = $type_id;
        $info = Dever::db('community/comment')->$method($where);
        $data['info'] = array();
        $data['total'] = Dever::total();
        if ($info) {
            foreach ($info as $k => $v) {
            	$data['info'][$k]['uid'] = $v['uid'];
                $data['info'][$k]['content'] = $v['content'];
                if ($v['pic']) {
                    $data['info'][$k]['pic'] = explode(',', $v['pic']);
                }
                if ($user) {
                    $data['info'][$k]['user'] = Dever::load('collection/lib/user')->get($v['uid'], $collection_id);
                    $data['info'][$k]['cdate_string'] = Dever::mdate($v['cdate'], 2);
                }
            }
        }

        return $data;
    }

    # 发表信息
    public function submit($uid, $id, $type, $pic, $content, $score_type = false, $score_type_id = false)
    {
        # 如果是商品,要先验证是否购买
        if ($type == 'content/product') {

        }
        $where['uid'] = $uid;
        $where['type_id'] = $id;
        $where['type'] = $type;
        $where['content'] = $content;
        if ($pic) {
            $where['pic'] = $pic;
        }
        $table = 'community/comment';
        $info = false;
        if (!$info) {
            Dever::db($table)->insert($where);
            Dever::score($uid, 'submit_comment', '发布弹幕/评论', false, false, false, $score_type, $score_type_id);
        }

        return true;
    }
}