From d1ba8f1a21e8f7b9349370790ad808feb40beffb Mon Sep 17 00:00:00 2001 From: DZywolf <34007722+DZywolf@users.noreply.github.com> Date: Sun, 11 Dec 2022 04:02:17 -0300 Subject: [PATCH] Initial commit --- .gitattributes | 2 + .github/ISSUE_TEMPLATE/bug_report.yml | 43 +++++ .github/ISSUE_TEMPLATE/config.yml | 5 + .github/README.md | 18 ++ .github/dependabot.yml | 10 ++ .github/release.yml | 22 +++ .github/scripts/build-zip | 9 + .github/workflows/release.yml | 30 ++++ .gitignore | 67 ++++++++ LICENSE | 21 +++ config/migration.php | 35 ++++ config/module.php | 13 ++ config/routes.php | 4 + controllers/Pvp.php | 36 ++++ controllers/index.html | 9 + index.html | 9 + language/english/index.html | 9 + language/english/pvp_lang.php | 18 ++ language/index.html | 9 + language/spanish/index.html | 9 + language/spanish/pvp_lang.php | 18 ++ migrations/20220920120000_add_permissions.php | 35 ++++ models/Pvp_model.php | 94 +++++++++++ models/index.html | 9 + views/index.html | 9 + views/index.php | 154 ++++++++++++++++++ 26 files changed, 697 insertions(+) create mode 100644 .gitattributes create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/README.md create mode 100644 .github/dependabot.yml create mode 100644 .github/release.yml create mode 100644 .github/scripts/build-zip create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 config/migration.php create mode 100644 config/module.php create mode 100644 config/routes.php create mode 100644 controllers/Pvp.php create mode 100644 controllers/index.html create mode 100644 index.html create mode 100644 language/english/index.html create mode 100644 language/english/pvp_lang.php create mode 100644 language/index.html create mode 100644 language/spanish/index.html create mode 100644 language/spanish/pvp_lang.php create mode 100644 migrations/20220920120000_add_permissions.php create mode 100644 models/Pvp_model.php create mode 100644 models/index.html create mode 100644 views/index.html create mode 100644 views/index.php diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..aacb20e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/.gitattributes export-ignore +/.github export-ignore diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..50448b6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,43 @@ +name: 🐛 Bug Report +description: Create a Bug Report +title: "🐛 [Bug Report]: " +labels: ['bug'] +body: + - type: markdown + attributes: + value: | + Hello, thanks for taking the time to fill out this bug report! + + Before you begin, **please ensure there is no existing open or closed issue related to your report**. + + --- + + - type: input + id: module-version + attributes: + label: Module Version + description: e.g. 1.0.0 + validations: + required: true + + - type: textarea + id: what-happened + attributes: + label: What happened? + description: Describe the issue in detail. + validations: + required: true + + - type: textarea + id: issue-reproduce + attributes: + label: How can the issue be reproduced? + description: Describe steps to reproduce the behavior. + validations: + required: true + + - type: textarea + id: issue-screenshots + attributes: + label: Screenshots + description: Provide screenshots here or share links. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..d299ed6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: WoW-CMS Community Support + url: https://discord.wow-cms.com + about: Join our community! Here you can get a faster responses about an issue. diff --git a/.github/README.md b/.github/README.md new file mode 100644 index 0000000..e8fbf5f --- /dev/null +++ b/.github/README.md @@ -0,0 +1,18 @@ +# _PvP Module_ + +[![Version](https://img.shields.io/github/v/release/wow-cms/bc-pvp?color=green&include_prereleases&logo=github&sort=semver&style=flat-square)](https://github.com/WoW-CMS/bc-pvp/releases) +[![License](https://img.shields.io/github/license/wow-cms/bc-pvp?color=blue&style=flat-square)](../LICENSE) + +## Requirements + +1. **BlizzCMS version** 2.0.0+ + +## Contributors + +Thanks to everyone who has contributed! + +[![Contributors](https://contrib.rocks/image?repo=wow-cms/bc-pvp)](https://github.com/WoW-CMS/bc-pvp/graphs/contributors) + +## License + +This module is released under the [MIT License](../LICENSE). diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..7ac299c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 + +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + ignore: + - dependency-name: "*" + update-types: ["version-update:semver-minor", "version-update:semver-patch"] diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..bff7d1b --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,22 @@ +changelog: + exclude: + authors: + - dependabot + categories: + - title: 🚨 Breaking Changes + labels: + - 'breaking change' + - title: 🐛 Bug Fixes + labels: + - bug + - title: ✨ New Features + labels: + - 'new feature' + - title: 🚀 Enhancements + labels: + - enhancement + - refactor + - 'missing feature' + - title: ⚙️ Dependency updates + labels: + - dependencies diff --git a/.github/scripts/build-zip b/.github/scripts/build-zip new file mode 100644 index 0000000..d95b9b1 --- /dev/null +++ b/.github/scripts/build-zip @@ -0,0 +1,9 @@ +#!/bin/bash + +# Variables +NAME=$1 + +# Create zip archive +zip -r ${NAME}.zip . -x \ + *.git* \ + .github/\* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..10c6aff --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Release + +on: + push: + tags: + - "v*.*.*" + +jobs: + build: + name: Build release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get tag version + id: get_version + run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_OUTPUT + + - name: Run script + run: | + chmod +x ./.github/scripts/build-zip + ./.github/scripts/build-zip pvp-${{ steps.get_version.outputs.RELEASE_VERSION }} + + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: pvp-${{ steps.get_version.outputs.RELEASE_VERSION }}.zip diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67ec441 --- /dev/null +++ b/.gitignore @@ -0,0 +1,67 @@ +#------------------------- +# Operating Specific Junk Files +#------------------------- + +# OS X +.DS_Store +.AppleDouble +.LSOverride + +# OS X Thumbnails +._* + +# Windows image file caches +Thumbs.db +ehthumbs.db +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Linux +*~ + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +#------------------------- +# IDE / Development Files +#------------------------- + +# Jetbrains editors (PHPStorm, etc) +.idea/ +*.iml + +# Netbeans +nbproject/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml +.nb-gradle/ + +# Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache +*.sublime-workspace +*.sublime-project +.phpintel +/api/ + +# Visual Studio Code +.vscode/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c6bc7eb --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 - 2022, WoW-CMS + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/config/migration.php b/config/migration.php new file mode 100644 index 0000000..4a65cf1 --- /dev/null +++ b/config/migration.php @@ -0,0 +1,35 @@ + 'PvP', + 'description' => 'Statistics page of the best players of each realm', + 'version' => '1.0.0', + 'author' => [ + 'name' => 'WoW-CMS', + 'website' => 'https://wow-cms.com' + ], + 'dashboard' => '' +]; diff --git a/config/routes.php b/config/routes.php new file mode 100644 index 0000000..60144cc --- /dev/null +++ b/config/routes.php @@ -0,0 +1,4 @@ +load->model('pvp_model'); + + $this->load->language('pvp'); + } + + public function index() + { + require_permission('view.pvp'); + + $data = [ + 'realms' => $this->realm_model->find_all() + ]; + + $this->template->title(lang('pvp_statistics'), config_item('app_name')); + + $this->template->build('index', $data); + } +} diff --git a/controllers/index.html b/controllers/index.html new file mode 100644 index 0000000..eebf8ec --- /dev/null +++ b/controllers/index.html @@ -0,0 +1,9 @@ + + + + 403 Forbidden + + +

Directory access is forbidden.

+ + diff --git a/index.html b/index.html new file mode 100644 index 0000000..eebf8ec --- /dev/null +++ b/index.html @@ -0,0 +1,9 @@ + + + + 403 Forbidden + + +

Directory access is forbidden.

+ + diff --git a/language/english/index.html b/language/english/index.html new file mode 100644 index 0000000..eebf8ec --- /dev/null +++ b/language/english/index.html @@ -0,0 +1,9 @@ + + + + 403 Forbidden + + +

Directory access is forbidden.

+ + diff --git a/language/english/pvp_lang.php b/language/english/pvp_lang.php new file mode 100644 index 0000000..8b68b1f --- /dev/null +++ b/language/english/pvp_lang.php @@ -0,0 +1,18 @@ + + + + 403 Forbidden + + +

Directory access is forbidden.

+ + diff --git a/language/spanish/index.html b/language/spanish/index.html new file mode 100644 index 0000000..eebf8ec --- /dev/null +++ b/language/spanish/index.html @@ -0,0 +1,9 @@ + + + + 403 Forbidden + + +

Directory access is forbidden.

+ + diff --git a/language/spanish/pvp_lang.php b/language/spanish/pvp_lang.php new file mode 100644 index 0000000..98ffc52 --- /dev/null +++ b/language/spanish/pvp_lang.php @@ -0,0 +1,18 @@ +permission_model->insert_batch([ + ['key' => 'view.pvp', 'module' => 'pvp', 'description' => 'Can view pvp page'] + ]); + + $permissions = $this->permission_model->find_all(['module' => 'pvp']); + $permsLinked = []; + + foreach ($permissions as $permission) { + $permsLinked[] = ['role_id' => '1', 'permission_id' => $permission->id]; + $permsLinked[] = ['role_id' => '2', 'permission_id' => $permission->id]; + $permsLinked[] = ['role_id' => '3', 'permission_id' => $permission->id]; + $permsLinked[] = ['role_id' => '4', 'permission_id' => $permission->id]; + $permsLinked[] = ['role_id' => '5', 'permission_id' => $permission->id]; + } + + $this->role_permission_model->insert_batch($permsLinked); + } + + public function down() + { + $permissions = $this->permission_model->find_all(['module' => 'pvp'], 'array'); + $permissionsIds = array_column($permissions, 'id'); + + if ($permissionsIds !== []) { + $this->permission_model->delete_in('id', $permissionsIds); + } + } +} diff --git a/models/Pvp_model.php b/models/Pvp_model.php new file mode 100644 index 0000000..c899610 --- /dev/null +++ b/models/Pvp_model.php @@ -0,0 +1,94 @@ +server_characters_model->connect($realm) + ->select('name, race, class, gender, level, totalKills, todayKills, yesterdayKills') + ->where('name !=', '') + ->order_by('totalKills', 'DESC') + ->limit($limit) + ->get('characters') + ->result(); + } + + /** + * Get the top teams in the arena + * + * @param int $realm + * @param int $type + * @param int $limit + * @return array + */ + public function top_teams($realm, $type = 2, $limit = 10) + { + $emulator = config_item('emulator'); + $database = $this->server_characters_model->connect($realm); + + if (in_array($emulator, ['cmangos', 'mangos'], true)) { + return $database->select('arena_team.name, arena_team.arenateamid, arena_team_stats.rating, arena_team_stats.wins_season AS seasonwins') + ->from('arena_team') + ->join('arena_team_stats', 'arena_team.arenateamid = arena_team_stats.arenateamid') + ->where('arena_team.type', $type) + ->order_by('arena_team_stats.rating', 'DESC') + ->limit($limit) + ->get() + ->result(); + } + + return $database->select('name, rating, seasonWins AS seasonwins, arenaTeamId AS arenateamid') + ->where('type', $type) + ->order_by('rating', 'DESC') + ->limit($limit) + ->get('arena_team') + ->result(); + } + + /** + * Get the arena team members of a realm + * + * @param int $realm + * @param int $team + * @return array + */ + public function team_members($realm, $team) + { + $emulator = config_item('emulator'); + $database = $this->server_characters_model->connect($realm); + + if (in_array($emulator, ['cmangos', 'mangos'], true)) { + return $database->select('arena_team_member.guid, arena_team_member.played_week AS weekgames, arena_team_member.wons_week AS weekwins, arena_team_member.played_season AS seasongames, arena_team_member.wons_season AS seasonwins, arena_team_member.personal_rating AS personalrating, characters.name, characters.race, characters.class, characters.gender') + ->from('arena_team_member') + ->join('characters', 'arena_team_member.guid = characters.guid') + ->where('arena_team_member.arenateamid', $team) + ->get() + ->result(); + } + + return $database->select('arena_team_member.guid, arena_team_member.weekGames AS weekgames, arena_team_member.weekWins AS weekwins, arena_team_member.seasonGames AS seasongames, arena_team_member.seasonWins AS seasonwins, arena_team_member.personalRating AS personalrating, characters.name, characters.race, characters.class, characters.gender') + ->from('arena_team_member') + ->join('characters', 'arena_team_member.guid = characters.guid') + ->where('arena_team_member.arenaTeamId', $team) + ->get() + ->result(); + } +} diff --git a/models/index.html b/models/index.html new file mode 100644 index 0000000..eebf8ec --- /dev/null +++ b/models/index.html @@ -0,0 +1,9 @@ + + + + 403 Forbidden + + +

Directory access is forbidden.

+ + diff --git a/views/index.html b/views/index.html new file mode 100644 index 0000000..eebf8ec --- /dev/null +++ b/views/index.html @@ -0,0 +1,9 @@ + + + + 403 Forbidden + + +

Directory access is forbidden.

+ + diff --git a/views/index.php b/views/index.php new file mode 100644 index 0000000..c009519 --- /dev/null +++ b/views/index.php @@ -0,0 +1,154 @@ +
+
+
+
+
    +
  • +
+

+
+
+
+
+
+
+
+

+
+ + + +
+
+
+ +
    + +
  • +
    +
    +
    +
    +
    +

    +
    +
    +
    + + + pvp_model->top_teams($realm->id) as $t => $team): ?> + + + + + + +
    +
    name ?>
    +

    rating ?>

    + pvp_model->team_members($realm->id, $team->arenateamid) as $member): ?> + Class + +
    +
    +
    +
    +
    +
    +
    +
    +

    +
    +
    +
    + + + pvp_model->top_teams($realm->id, 3) as $t => $team): ?> + + + + + + +
    +
    name ?>
    +

    rating ?>

    + pvp_model->team_members($realm->id, $team->arenateamid) as $member): ?> + Class + +
    +
    +
    +
    +
    +
    +
    +
    +

    +
    +
    +
    + + + pvp_model->top_teams($realm->id, 5) as $t => $team): ?> + + + + + + +
    +
    name ?>
    +

    rating ?>

    + pvp_model->team_members($realm->id, $team->arenateamid) as $member): ?> + Class + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + pvp_model->top_pvp($realm->id) as $p => $player): ?> + + + + + + + + + + +
    name ?>level ?><?= race_name($player->race) ?><?= class_name($player->class) ?>totalKills ?>
    +
    +
    +
    +
  • + +
+ +
+
+
+