<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class DigAction extends BbsAction
{
    public function run()
    {
        $this->getController()->isLogin();
        $tid = $this->getTid();
        $thread = $this->getExistsThread($tid);
        $type = S::gp('t','G');
        !in_array($type, array('dig','fight')) && $this->showMessage('非法操作，请返回');
        
        if (false !== strpos($thread['diger'],','.$this->uid().','))
        {
            throw new iSystemException('您已经评价过了');
        }
        
        $update = empty($thread['diger']) ? ','.$this->uid().',' : $thread['diger'].$this->uid().',';
        $this->db()->update(Threads::table())->incrField(array($type=>1))->where('id='.$tid)->q();
        $this->db()->update(ThreadsData::table())->value(array('diger'=>$update))->where('tid='.$tid)->q();
        
        $feed = '{{'.$this->uid().'}}评价了帖子《[url='.staticUrl('system',array('s'=>'bbs','a'=>'thread','tid'=>$tid)).']'.$thread['subject'].'[/url]》';
        iFeed::single()->create($feed, $this->uid());
        
        iforward(url('system',array('s'=>'bbs','a'=>'thread','tid'=>$tid)));
    }
}