public function _saveMasteries($mastery_data) { $masteries_data = json_decode($mastery_data); $insert_pages_data = array(); $insert_masteries_data = array(); //var_dump($runes_data); $query_clean_masteries = Core::lib('Database')->newQuery('clean_masteries'); $query_clean_pages = Core::lib('Database')->newQuery('clean_pages'); $query_clean_masteries->target('masteries'); $query_clean_pages->target('masterypages'); foreach ($masteries_data as $dataset) { $query_clean_masteries->andWhere('summoner_id', "=", $dataset->summonerId); $query_clean_pages->andWhere('summoner_id', "=", $dataset->summonerId); foreach ($dataset->pages as $page) { $query_clean_masteries->andWhere('mastery_page', "!=", $page->id); $query_clean_pages->andWhere('id', "!=", $page->id); $insert_pages_data[] = array('id' => $page->id, 'summoner_id' => $dataset->summonerId, 'name' => $page->name, 'current' => $page->current == true ? 1 : 0); if (property_exists($page, "masteries")) { foreach ($page->masteries as $rune) { $insert_masteries_data[] = array('mastery_page' => $page->id, 'mastery_id' => $rune->id, 'rank' => $rune->rank, 'summoner_id' => $dataset->summonerId); } } } } $query_pages = Core::lib('Database')->newQuery('save_pages'); $query_runes = Core::lib('Database')->newQuery('save_runes'); $query_clean_masteries->delete(); $query_clean_pages->delete(); $query_pages->target('masterypages')->onDuplicate('id = VALUES(id), summoner_id = VALUES(summoner_id), name = VALUES(name), current = VALUES(current)')->multiInsert($insert_pages_data); $query_runes->target('masteries')->onDuplicate('mastery_page = VALUES(mastery_page), mastery_id = VALUES(mastery_id), rank = VALUES(rank), summoner_id = VALUES(summoner_id)')->multiInsert($insert_masteries_data); }
public function registerPluginConfig($namespace, $config) { $rewrite = $config->config['plugin']; $conf = $config->config['config']; Core::lib('Rewrite')->registerRewriteFromPluginConfig($namespace, $rewrite); Core::lib('Config')->loadConfigArray($conf); }
public function registerInterface($name, $class) { if (isset($this->_interfaces[$name])) { \Nightshade\Core::lib('Logger')->log(sprintf("Duplicated interface \"%s\": %s - %s", $name, get_class($this->_interfaces[$name]), get_class($class))); } $this->_interfaces[$name] = $class; }
private function _saveRunes($runes_data) { $runes_data = json_decode($runes_data); $insert_pages_data = array(); $insert_runes_data = array(); //var_dump($runes_data); $query_clean_runes = Core::lib('Database')->newQuery('clean_runes'); $query_clean_pages = Core::lib('Database')->newQuery('clean_pages'); $query_clean_runes->target('runes'); $query_clean_pages->target('runepages'); foreach ($runes_data as $dataset) { $query_clean_runes->andWhere('summoner_id', "=", $dataset->summonerId); $query_clean_pages->andWhere('summoner_id', "=", $dataset->summonerId); foreach ($dataset->pages as $page) { $query_clean_runes->andWhere('rune_page', "!=", $page->id); $query_clean_pages->andWhere('id', "!=", $page->id); $insert_pages_data[] = array('id' => $page->id, 'summoner_id' => $dataset->summonerId, 'name' => $page->name, 'current' => $page->current == true ? 1 : 0); foreach ($page->slots as $rune) { $insert_runes_data[] = array('rune_page' => $page->id, 'slot_id' => $rune->runeSlotId, 'rune_id' => $rune->runeId, 'summoner_id' => $dataset->summonerId); } } } var_dump($insert_runes_data); $query_pages = Core::lib('Database')->newQuery('save_pages'); $query_runes = Core::lib('Database')->newQuery('save_runes'); $query_clean_runes->delete(); $query_clean_pages->delete(); $query_pages->target('runepages')->onDuplicate('id = VALUES(id), summoner_id = VALUES(summoner_id), name = VALUES(name), current = VALUES(current)')->multiInsert($insert_pages_data); $query_runes->target('runes')->onDuplicate('rune_page = VALUES(rune_page), slot_id = VALUES(slot_id), rune_id = VALUES(rune_id), summoner_id = VALUES(summoner_id)')->multiInsert($insert_runes_data); }
public function toHtml() { $region = Core::lib('Param')->getParam('region'); $url = Core::plugin('NoxusApi')->getApiUrl($region); $url = str_replace("#request#", "observer-mode/rest/featured", $url); $response = Core::plugin('NoxusApi')->sendRequest($url); return $response; }
public function names() { $region = Core::lib('Param')->getParam('region'); $summoner = Core::lib('Param')->getParam('summoner'); $url = Core::plugin('NoxusApi')->getApiUrl($region); $url = str_replace("#request#", "api/lol/{$region}/v{$this->_api_version}/summoner/{$summoner}/name", $url); $response = Core::plugin('NoxusApi')->sendRequest($url); return $response; }
/** * @param $host * @param $username * @param $pass * @param $db * * Establish a connection */ public function create($host, $username, $pass, $db) { try { $this->_db = new \MySQLi($host, $username, $pass, $db); \Nightshade\Core::lib('Hooks')->triggerHook('database_connected'); } catch (\Exception $e) { trigger_error($e->getMessage()); } }
/** * @param $summoner_data */ private function _saveSummoners($summoner_data) { $summoner_data = json_decode($summoner_data); $insert_data = array(); foreach ($summoner_data as $dataset) { $insert_data[] = array('id' => $dataset->id, 'name' => (string) $dataset->name, 'level' => $dataset->summonerLevel, 'icon' => $dataset->profileIconId, 'last_action' => $dataset->revisionDate); } $query = Core::lib('Database')->newQuery('save_summoner'); //$query = new \Nightshade\Lib\Database\Classes\Query(Core::lib('Database')); $query->target('summoner')->onDuplicate('name = VALUES(name), level = VALUES(level), icon = VALUES(icon), last_action = VALUES(last_action)')->multiInsert($insert_data); }
public function getCached($request, $force_cache = false) { $query = Core::lib('Database')->newQuery('api_cache'); //$query = new \Nightshade\Lib\Database\Classes\Query(Core::lib('Database')); $query->target('api_cache')->select('*')->where('request', '=', $request); if (!$force_cache) { $query->andWhere('timestamp > (NOW() - INTERVAL 1 MINUTE)'); } $response = $query->limit(1)->get(); if (count($response) >= 1) { $this->_was_cache = true; return $response[0]; } $this->_was_cache = false; return false; }
function registerConfig() { Core::lib('Plugin')->registerPluginConfig(__NAMESPACE__, new Config\Config()); }