/** * * @param array $params require: * 'prizedTime' => (datetime) date time when user were awarded with this medal * 'type' => medal type */ public function __construct($params) { $this->medalId = $params['medalId']; $details = \lib\Controllers\MedalsController::getMedalConfigByMedalId($this->medalId); $this->conditions = $details['conditions']; $this->name = $details['name']; $this->description = $details['description']; $this->dateIntroduced = $details['dateIntroduced']; if (isset($params['prizedTime'])) { $this->prizedTime = $params['prizedTime']; $this->level = (int) $params['level']; $this->setImage(); } $this->config = \lib\Objects\OcConfig\OcConfig::instance(); }
public function loadMedalsFromDb() { $db = \lib\Database\DataBaseSingleton::Instance(); $query = 'SELECT `medal_type`, `prized_time`, `medal_level` FROM `medals` WHERE `user_id`=:1'; $db->multiVariableQuery($query, $this->userId); $medalsDb = $db->dbResultFetchAll(); $this->medals = new \ArrayObject(); $medalController = new MedalsController(); foreach ($medalsDb as $medalRow) { $this->medals[] = $medalController->getMedal(array('prizedTime' => $medalRow['prized_time'], 'medalId' => (int) $medalRow['medal_type'], 'level' => $medalRow['medal_level'])); // $this->medals[] = new \lib\Objects\Medals\Medal(array('prizedTime' => $medalRow['prized_time'], 'medalId' => (int) $medalRow['medal_type'], 'level' => $medalRow['medal_level'])); } }