Back to PhocacartReward class

Method getTotalPointsByUserId

public
getTotalPointsByUserId
(mixed $userId)

Method getTotalPointsByUserId - Source code

public function getTotalPointsByUserId($userId)
{
    if ($userId > 0) {
        if (empty($this->total[$userId])) {
            $db = Factory::getDBO();
            $query = 'SELECT SUM(a.points) FROM #__phocacart_reward_points AS a' . ' WHERE a.user_id = ' . (int) $userId . ' AND a.published = 1' . ' GROUP BY a.user_id' . ' ORDER BY a.id';
            $db->setQuery($query);
            $total = $db->loadResult();
            if (!$total) {
                $total = 0;
            }
            $this->total[$userId] = (int) $total;
        }
        return $this->total[$userId];
    }
    return 0;
}