<?php

/*
 * @component UserPoints
 * @copyright Copyright (C) 2015-2022 Bernard Gilly - Adrien Roussel - Martin Brampton
 * @license : GNU/GPL
 * @Website : https://remository.com
 */

namespace BlackSheepResearch\Component\UserPoints\Site\Problems;

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\User\User;

class QRCodeTrack extends ProblemBase {

    protected static $fieldnames = [];
    protected static $fieldtypes = [];
    protected static $count = -1;
    protected static $tablename = '#__alpha_userpoints_qrcodetrack';
    protected static $updatetable = '#__alpha_userpoints_qrcodetrack';
    protected static $keyname = 'id';

    public function __construct(int $id = 0) {
        parent::__construct();
        if ($id) {
            $this->getOneRow($id);
        }
    }
    
    public static function withTrackid (string $trackID) {
        $qr = new self();
        $db = SQL::getInstance();
        $db->setQuery(sprintf("SELECT id FROM `%s` WHERE `trackid` = %s", self::$tablename, $db->quote($trackID)));
        $result = $db->loadResult();
        if (is_object($result)) {
            $qr->problem_object = $result;
        }
        return $qr;
    }
}
