Ejemplo n.º 1
0
/**
 * @author  ryan <*****@*****.**>
 */
function attitude($type)
{
    if (!$GLOBALS['has_login']) {
        return;
    }
    $class = camel2under($type);
    $map = array('like' => 1, 'hate' => 0);
    $target = _req('target');
    $action = _req('action');
    $info = array($type => $target, 'user' => $GLOBALS['user'], '`like`' => $map[$action]);
    $at = Attitude::create($info);
    if ($at) {
        $info = array('user' => $GLOBALS['user'], 'action' => $action, 'object' => $target);
        $act = Activity::create($info);
        // inform author
        $comment = new $class($target);
        $info = array('user' => $comment->user, 'activity' => $act);
        Timeline::create($info);
    }
    $o = new $class($target);
    echo $o->{$action . 'Count'}();
}
Ejemplo n.º 2
0
 public function attitudeByUser($attitude, User $user)
 {
     $map = array('hate' => 0, 'like' => 1);
     return Attitude::search()->filterBy('comment', $this)->filterBy('like', $map[$attitude])->filterBy('user', $user)->count();
 }